显示一位作者的帖子,并且只显示当前类别中的帖子(wordpress)

  • 本文关键字:显示 wordpress 一位 wordpress
  • 更新时间 :
  • 英文 :


我需要你的帮助来解决我的问题。

所以,我做不到的:例如,我有一个类别"新闻",这个类别有一些子类别"政治"、"体育"、"生活"等。

在侧边栏中显示了作者的姓名列表,如果我点击某个类别中的某个作者,我只需要显示该作者和当前类别子类别中的帖子。

我该如何创建它?我想它可以通过pre_get_posts创建,但不确定。

我找到了解决方案。

显示所有在特定类别中写过帖子的用户(我创建了一个头像/名字的旋转滑块)。然后我生成链接并在最后添加当前类别。

<ul id="carousel">                                                                                                                                                                                                      
<?php
$current_category = single_cat_title("", false);
$author_array = array();
$args = array(
'numberposts' => -1,
'category_name' => $current_category,
'orderby' => 'author',
'order' => 'ASC'
);
$cat_posts = get_posts($args);
foreach ($cat_posts as $cat_post) :
if (!in_array($cat_post->post_author,$author_array)) {
$author_array[] = $cat_post->post_author;
}
endforeach;
foreach ($author_array as $author) :
$auth = get_userdata($author)->display_name;
$langCur = pll_default_language();
$auth_link = get_userdata($author)->user_login;
$homeurl = home_url();
echo "<li>";
echo "<a href='".$homeurl."/author/".$auth_link."/?cat=".get_cat_ID( $current_category )."' title=''>";
echo get_avatar( $author, $size = '140' );
echo "<span>";
echo $auth;
echo "</span>";
echo "</a></li>";
endforeach;
?>
</ul>

最新更新