/ 软件 / 1281阅

实现了存档页面显示“最多点赞”、“最多阅读”等功能

经过Bigfa指点,找到了《利用get_posts获取特定文章》,恍然大悟的结果是实现了页面显示“最多点赞”、“最多阅读”等功能,见旅行漫记评论页竹炉山房评论页

这种成就感,实在是高潮迭起啊!

独乐乐,不若众乐乐。

<h3><?php _e('最多点赞','Puma_child') ?></h3>
<ul class="posts-archive-list">		            				            
<?php //Get the most liked posts
	global $posts,$post;
	$args = array(
	'posts_per_page' => 10,
	'meta_key' => '_post_like',
	'orderby' => 'meta_value_num'
	);
	$postslist = get_posts( $args );
	foreach ( $postslist as $post ) :
		setup_postdata( $post ); ?>
   		<li><span style="font-size: 0.9rem;"><?php the_time(get_option('date_format')); ?>&nbsp;&nbsp;</span><a rel="bookmark" class="title" href="<?php echo wp_get_shortlink( $post->ID );?>"><?php the_title();?></a><span style="font-size: 0.9rem;">&nbsp;&nbsp;<?php echo get_post_meta($post->ID,'_post_like',true)?>人点赞.</span></li>
<?php endforeach;
wp_reset_postdata();?>
</ul>	


<h3><?php _e('近期点赞','Puma_child') ?></h3>
<ul class="posts-archive-list">	            				            
<?php //Get the recent liked posts
	global $posts,$post;
	$args = array(
	'posts_per_page' => 10,
	'meta_key' => '_post_like',
	'orderby' => 'meta_value_num',
	'date_query' => array(
	   array(
	   'column' => 'post_date_gmt',
	   'after'  => '3 months ago',
	   )
	)
);
$postslist = get_posts( $args );
foreach ( $postslist as $post ) :
	setup_postdata( $post ); ?>
	<li><span style="font-size: 0.9rem;"><?php the_time(get_option('date_format')); ?>&nbsp;&nbsp;</span><a rel="bookmark" class="title" href="<?php echo wp_get_shortlink( $post->ID );?>"><?php the_title();?></a><span style="font-size: 0.9rem;">&nbsp;&nbsp;<?php echo get_post_meta($post->ID,'_post_like',true)?>人点赞.</span></li>
<?php endforeach;
	wp_reset_postdata();?>
</ul>
	
<h3><?php _e('最多阅读','Puma_child') ?></h3>
    <ul class="posts-archive-list">		            				            
	<?php //Get the most read posts
	global $posts,$post;
	$args = array(
	'posts_per_page' => 10,
	'meta_key' => 'views',
	'orderby' => 'meta_value_num'
);
$postslist = get_posts( $args );
foreach ( $postslist as $post ) :
	setup_postdata( $post ); ?>
   <li><span style="font-size: 0.9rem;"><?php the_time(get_option('date_format')); ?>&nbsp;&nbsp;</span><a rel="bookmark" class="title" href="<?php echo wp_get_shortlink( $post->ID );?>"><?php the_title();?></a><span style="font-size: 0.9rem;">&nbsp;&nbsp;<?php echo get_post_meta($post->ID,'views',true)?>次阅读.</span></li>
<?php endforeach;
wp_reset_postdata();?>
</ul>

唯一的缺憾是不能实现显示近期被点赞的文章。

# 写于九年前,改于二年前
           

4

  1. 上

    先收藏一下 以备不时之需

    Chrome 47 · iPhone iOS 9.1
    1. S̆̈

      @上🙂

      Safari 7 · iPhone iOS 9.1
  2. Betty

    强烈要求加入近期最多被吐槽和扔鸡蛋等功能~

    Mozilla Compatible · iPhone iOS 9.1
    1. S̆̈

      @Betty哈哈,这跟“赞”其实是一个机理!

      Safari 7 · iPhone iOS 9.1

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注