经过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')); ?> </span><a rel="bookmark" class="title" href="<?php echo wp_get_shortlink( $post->ID );?>"><?php the_title();?></a><span style="font-size: 0.9rem;"> <?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')); ?> </span><a rel="bookmark" class="title" href="<?php echo wp_get_shortlink( $post->ID );?>"><?php the_title();?></a><span style="font-size: 0.9rem;"> <?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')); ?> </span><a rel="bookmark" class="title" href="<?php echo wp_get_shortlink( $post->ID );?>"><?php the_title();?></a><span style="font-size: 0.9rem;"> <?php echo get_post_meta($post->ID,'views',true)?>次阅读.</span></li>
<?php endforeach;
wp_reset_postdata();?>
</ul>
唯一的缺憾是不能实现显示近期被点赞的文章。
上 江苏
先收藏一下 以备不时之需
九年前 Chrome 47 · iPhone iOS 9.1S 江苏 *
@上 🙂
九年前 Safari 7 · iPhone iOS 9.1Betty 上海
强烈要求加入近期最多被吐槽和扔鸡蛋等功能~
九年前 Mozilla Compatible · iPhone iOS 9.1S 江苏 *
@Betty 哈哈,这跟“赞”其实是一个机理!
九年前 Safari 7 · iPhone iOS 9.1