学做网站培训课程介绍

当前位置:

WordPress网站制作热门文章排行榜(浏览量排序)

使用Wordpress做网站,有时需要在网站的侧边栏调用热门文章,我们经常是按评论数进行排序的,今天介绍一下如何调用以浏览量排序的热门文章的方法。(相关教程:wordpress如何调用某一个分类下的热门文章(热评文章)

Wordpress网站调用热门文章排行榜

方法/步骤

  1. 先要在自己的WORDPRESS网站模板函数文件functions.php中添加以下的浏览量函数代码,用于调用文章浏览量。代码见:wordpress免插件显示文章浏览量次数
  2. 然后在需要调用按浏览量排序的热门文章位置,使用以下的代码进行调用文章列表;
    
    
     <ul>
               <?php $args=array(
             'meta_key' => 'views',
             'orderby' => 'meta_value_num',
             'posts_per_page'=>6,
             'order' => 'DESC'
        );
        query_posts($args);  while (have_posts()) : the_post();?>
           <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><span class="kc-view fright">浏览:<?php setPostViews(get_the_ID()); echo number_format(getPostViews(get_the_ID())); ?></span></li>    
        <?php endwhile;wp_reset_query();?>
            </ul>
  3. 这样就可以调用出用户浏览最多的6篇文章了。

更新:如果想对显示的文章列表做控制,可以使用以下的代码:

1、排除置顶文章


<ul>
<?php $args=array(
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'post__not_in' => get_option( 'sticky_posts' ),
'posts_per_page'=>6,
'order' => 'DESC'
);
query_posts($args); while (have_posts()) : the_post();?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><span class="kc-view fright">浏览:<?php setPostViews(get_the_ID()); echo number_format(getPostViews(get_the_ID())); ?></span></li>
<?php endwhile;wp_reset_query();?>
</ul>

2、排除指定分类下的文章


<ul>
<?php $args=array(
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'post__not_in' => get_option( 'sticky_posts' ),
'category__not_in' => array('1','2'),
'posts_per_page'=>6,
'order' => 'DESC'
);
query_posts($args); while (have_posts()) : the_post();?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><span class="kc-view fright">浏览:<?php setPostViews(get_the_ID()); echo number_format(getPostViews(get_the_ID())); ?></span></li>
<?php endwhile;wp_reset_query();?>
</ul>

3、调用指定分类下的热门文章


<ul>
<?php $args=array(
'meta_key' => 'post_views_count',
'orderby' => 'meta_value_num',
'post__not_in' => get_option( 'sticky_posts' ),
'cat' => array('1','2'),
'posts_per_page'=>6,
'order' => 'DESC'
);
query_posts($args); while (have_posts()) : the_post();?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><span class="kc-view fright">浏览:<?php setPostViews(get_the_ID()); echo number_format(getPostViews(get_the_ID())); ?></span></li>
<?php endwhile;wp_reset_query();?>
</ul>

 

4、提取30天时间段浏览量最多的文章。


<?php
$date_query=array(
array(
'column' => 'post_date',
'before' => date('Y-m-d',time()+3600*24),
'after' =>date('Y-m-d',time()-3600*24*30) //此处30标示三十天内浏览量
)
);
?>
<?php
$args = array(
'posts_per_page' =>1,
'cat' =>26,
'post__in' => get_option( 'sticky_posts' ),
'ignore_sticky_posts' => 1,
'meta_key' => 'views',
'date_query' => $date_query,
'orderby'=> 'meta_value_num',
);
query_posts( $args ); while ( have_posts() ) : the_post();?>
<h4><b><a href="<?php the_permalink(); ?>"><?php echo mb_strimwidth(get_the_title(), 0,100, ''); ?></a>
</b></h4>
<?php endwhile;wp_reset_query();?>

发表评论

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

相关教程

  • 漂亮的wordpress淘客模板 图文教程 (111026 次浏览)
    今天再次给大家分享一款自己仿的一个wordpress淘客模板。这个模板是我自己在别人模板的基础上进行二次开发,自己比较喜欢。注意:此模板不支持IE6,
  • 用什么建网站?Wordpress建网站好不好?这些问题经常被新手问上问起。可以这样说,wordpress程序可以建各种类型的网站,它的功能强大之处令人称赞,
  • 做网站过程中,如果想对自己网站中的文章进行排序,就可以利用热门文章代码来自动调用,热门文章可以分为二种方法:按照文章浏览量和文章评论数。
  • wordpress程序是一个比较高效的网站制作程序,在学员学习如何做网站的时候,可以使用wp程序作为自己的首选建站程序,只要熟练的运用它的网站代码就可
  • 今天分享一款分享产品十佳排行淘客模板,操作简单淘客主题,很符合SEO ,安装即用,给新手少走弯路。该主题是静态页+文章页,首页有16个广告位置。
  • 使用Wordpress做网站,有时需要在网站的侧边栏调用热门文章,我们经常是按评论数进行排序的,今天介绍一下如何调用以浏览量排序的热门文章的方法。(
  • 我们做好了网站,为了体现网站的人气文章,可以在自己的网站上制作一个周排行榜或月排行榜,分别调用一周内网站文章浏览量最多的文章列表和一个月内浏
  • 软件介绍在我们做网站的过程中,希望自己做的的网站,别人在用不同浏览器浏览的时候,都不会错位,或者不显示。这就需要我们在做网站之前,对我们的
  • 在我们学习建网站过程中,使用火狐浏览器来辅助我们编辑网页,查看网页图片,修改网站代码.特别的方便.可以大大增加我们的工作效率.所在在学做网站论坛里
  • 插件介绍自己做网站时,如果想在网页上显示文章的浏览量,除了免插件实现文章浏览数之外,就是安装一个wordpress浏览量插件WP-PostViews。这个插件
  • 通过wordpress程序自己做网站时,如果想在网站上显示每片文章的浏览量,一般都会使用wordpress浏览量插件,它可以方便的统计我们网站的每篇文章的浏览
  • 织梦DEDECMS5.7这个版本存在一个问题,修改文章的同时也修改了文章的发布时间,这种情况下,如果我们调用最新文章时使用按“发布日期排序”,就会打乱原来