1.在模版中加入recent_comments.php文件,其代码如下:
| 代码如下 |
复制代码 |
|
<?php
$comments = get_comments('number=10&status=approve');
$true_comment_count = 0;
foreach($comments as $comment) :
$comment_type = get_comment_type();
if($comment_type == 'comment') {
$true_comment_count = $true_comment_count +1;
$comm_title = get_the_title($comment->comment_post_ID);
$comm_link = get_comment_link($comment->comment_ID);
$comm_comm_temp = get_comment($comment->comment_ID,ARRAY_A);
$comm_content = $comm_comm_temp['comment_content'];
?>
On: <?php echo $comm_title ?> Say:<?php echo $comm_content ?>
<?php
}
if($true_comment_count == 5) break;
endforeach;
?>
|
2.然后在sidebar.php你想要显示的位置中插入:
| 代码如下 |
复制代码 |
|
<?php include (TEMPLATEPATH . '/recent_comments.php'); ?>
|
WordPress获取当前分类的根分类id函数
只有自己动手了,后来使用了以下两个方法解决了问题!
| 代码如下 |
复制代码 |
|
function get_category_root_id($cat)
{
$this_category = get_category($cat); // 取得当前分类
while($this_category->category_parent) // 若当前分类有上级分类时,循环
{
$this_category = get_category($this_category->category_parent); // 将当前分类设为上级分类(往上爬)
}
return $this_category->term_id; // 返回根分类的id号
}
function fengzx_get_category_ID() {
$category = get_the_category();
return $category[0]->cat_ID;
}
|