我使用的是一个修改后的版本,我试图在侧栏中显示与当前帖子(除了当前帖子)相同类别的最新帖子。
我是这样开始的,但有些事情不太好:
$category = get_the_category($post->ID);
$current_cat = $category[0]->cat_name; //This will get me the first category assigned to the current post but since every post has only ONE cat. assigned to, it\'s good enough
//Next, in my sidebar widget I have this:
$my_query = new WP_Query(\'category_name=\'.$current_cat.\'&showposts=10\');
while ($my_query->have_posts()) : $my_query->the_post();
...display my titles here ...
unset($current_cat); //I\'m not sure I need to unset this variable?
endwhile;
我不是一个真正的程序员,所以我正在努力理解逻辑,但我想学习。非常感谢您的任何建议/帮助!
谢谢你,亚历克斯