板鄧網上找了很多文章,代碼都很復雜,不適合新手使用,下面板鄧分享最簡單方式就可以實現熱門文章調用:
1、安裝插件 WP-PostViews,設置好。
調用代碼如下:
<? $args=array( 'numberposts'=>8, 'orderby'=>'meta_value_num',//按點擊量排序 'meta_key'=>'views' ); $rand_posts=get_posts($args); foreach($rand_posts as $post){ setup_postdata($post); ?> <ul > <a href="<?php the_permalink(); ?>" title="<? the_title(); ?>"><?php the_title(); ?></a>
<? echo the_views(true, '閱讀( ',' )次','true');?> </ul> <?}?>