侧边栏php,尝试在侧边栏PHP中显示类别特定的注释

我试图仅在当前类别的侧边栏中显示评论。到目前为止,我有这样的:

但它不起作用,它在任何地方或任何地方都会显示0条评论。我不明白我做错了什么...

问题似乎是这个部分:

//类别(可以是父类别)

$ cat = get_query_var('cat');

$ category_parent = $ cat;

// Posts per page setting

$ppp = 8; //get_option('posts_per_page'); // either use the WordPress global Posts per page setting or set a custom one like $ppp = 10;

$custom_offset = 0; // If you are dealing with your custom pagination, then you can calculate the value of this offset using a formula

// category (can be a parent category)

$cat = get_query_var('cat');

$category_parent = $cat;

// lets fetch sub categories of this category and build an array

$categories = get_terms( 'category', array( 'child_of' => $category_parent, 'hide_empty' => false ) );

$category_list = array( $category_parent );

foreach( $categories as $term ) {

$category_list[] = (int) $term->term_id;

}

// fetch posts in all those categories

$posts = get_objects_in_term( $category_list, 'category' );

$sql = "SELECT comment_ID, comment_date, comment_content, comment_post_ID, user_id, comment_author

FROM {$wpdb->comments} WHERE

comment_post_ID in (".implode(',', $posts).") AND comment_approved = 1

ORDER by comment_date DESC LIMIT $ppp OFFSET $custom_offset";

$comments_list = $wpdb->get_results( $sql );

if ( count( $comments_list ) > 0 ) {

$date_format = get_option( 'date_format' );

foreach ( $comments_list as $comment ) {

?>

<?php echo get_avatar( $comment->user_id, 50 ); ?>

<?php echo($comment->comment_author); ?> commented on

<?php echo get_the_title ( $comment->comment_post_ID ); ?>

<?php echo($comment->comment_date); ?>

"<?php comment_excerpt(); ?>" Read More

}

} else {

echo '

No comments

';

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值