2014-04-17 104 views
0

我需要你的帮助来解决我的问题。显示一位作者的帖子,仅从当前类别(wordpress)

所以,我不能让: 举例来说,我有一个类别“新闻”,这一类有一些子类“政治”,“运动”,“生命”等

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

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

+0

http://stackoverflow.com/a/18512467/1071555 这几乎是我所需要的,但我需要动态地获取当前类的特定用户。我尝试从function.php获取类别ID,但我收到一个空的结果。怎么了? –

回答

0

我找到了解决方案。

显示所有甚至已经被写入特定类别的帖子的用户(我创建了它的头像/名称的旋转木马滑块)。然后我生成链接并在最后添加当前类别。

<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> 
相关问题