wordpress自定义“热门文章”小工具

注册函数:register_sidebar_widget

1.在functions.php添加注册函数

function mb_hot() { include(TEMPLATEPATH . '/hot.php'); }
if( function_exists( 'register_sidebar_widget' ) ) {
register_sidebar_widget('热门文章','mb_hot');
}

2.新建hot.php模板页面,将代码复制进去

<section class="widget widget_recent_entries">
<h3 class="widget-title">热门文章</h3>
<ul>
<?php query_posts('posts_per_page=6&caller_get_posts=1&orderby=comment_count'); ?>
<?php while (have_posts()) : the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>" class="text-h1" title="<?php the_title(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
</section>

这样你的小工具里面就多了一个 “热门文章”的小工具了

原文地址:https://www.cnblogs.com/lanne/p/15532207.html