用户登录
还没有账号?立即注册
用户注册
点击换图
投稿取消
文章分类:
还能输入300字

上传中....

如何不用插件而在WordPress边栏中显示热门内容

时间:2023-03-31 作者: 来源:顿格文库

有一些插件可以实现这个功能,但如果你不想用插件的话,可以考虑下面的方法。

很简单,把以下代码粘贴到sidebar.php里去:

<h2>Popular Posts</h2>

<ul>

<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");

foreach ($result as $post) {

setup_postdata($post);

$postid = $post->ID;

$title = $post->post_title;

$commentcount = $post->comment_count;

if ($commentcount !

= 0) { ?>

<li><a echo get_permalink($postid); ?>" title="<?php echo $title ?>">

<?php echo $title ?></a> {<?php echo $commentcount ?>}</li>

<?php } } ?>

</ul>

大功告成!

原文:How to: Display your most popular content in your blog sidebar


★本★文来源顿格文库,转载请注明出处!

热门关键词