经过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条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注