Php wp_query-显示选定类别中为该类别撰写文章的所有作者
我需要你的帮助,我是Php wp_query-显示选定类别中为该类别撰写文章的所有作者,php,wordpress,Php,Wordpress,我需要你的帮助,我是wp\u查询的新手 我不知道如何显示选定类别中为该类别撰写文章的所有作者。 这意味着我会在我的页面上,比如说:爱好 然后我想展示所有这类文章以及写这些文章的作者 我搜索了这么多,找到了这样的东西,但这不是我需要的>\u> 希望你明白我的意思 希望你能帮我:) 编辑: 啊,好的,谢谢你!我在我的代码上尝试了该代码,但在我的站点上没有发生任何事情:,D 我做错了什么/ <?php $get_cat_id = get_the_category(); $ar
wp\u查询的新手
我不知道如何显示选定类别中为该类别撰写文章的所有作者。
这意味着我会在我的页面上,比如说:爱好
然后我想展示所有这类文章以及写这些文章的作者
我搜索了这么多,找到了这样的东西,但这不是我需要的>\u>
希望你明白我的意思
希望你能帮我:)
编辑:
啊,好的,谢谢你!我在我的代码上尝试了该代码,但在我的站点上没有发生任何事情:,D
我做错了什么/
<?php
$get_cat_id = get_the_category();
$args = array(
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => array ( $get_cat_id),
)
)
);
$the_query = new WP_Query($args);
//the loop
$firstEntry = true;
if ( $the_query -> have_posts() ) {
while ( $the_query -> have_posts() ) {
echo $firstEntry ? '<article class="active">' : '<article>';
$firstEntry = false;
$the_query -> the_post();
$last = get_the_author_meta('last_name');
$first = get_the_author_meta('first_name');
echo '<h3 class="author"><a href="'. get_the_author_meta('display_name') . '">' . $first . " " . $last . '</a></h3>';
echo '<img src="<?php echo $template_uri; ?>/img/author_mini.jpg" alt="THOMAS SCHRÖDER" class="thumb-round">';
echo '</article>';
}
} else {
// no posts found
}
?>
您需要执行自定义WP查询
细分:
你需要知道你的帖子(以及它的类别)
然后查询所有帖子的类别
从这些帖子中可以找到作者
所以
然后在类别中foreach
post
get_the_author_id();
或者类似的东西。您需要将代码格式化为SO。谷歌怎么做,如果你不确定。做一些调试-你知道一些PHP
对吗?先试试这个->里面有很多代码。也许从少一点开始。只需显示作者姓名,然后添加其他姓名。不确定$the_query->the_post()代码>将在while循环中帮助您。另外看看WordPress的代码,我检查了数组等等,但我不知道为什么它不工作。。“if($the_query->have_posts())”有个问题,因为他甚至不完全在这个if语句中。。但是为什么呢/你查过var dump了,你有没有得到数据,我不明白你在说什么。在您的问题中添加一些输出。您需要阅读法典并理解has posts查询。是的,我会,我会将此发布在top EDIT2,sry上,因为我的英语不好:/
$get_cat_id = get_the_category();
$query = new wp_query($arr);
$arr = array(
'paged' => $paged,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => array ( $get_cat_id),
)
)
);
get_the_author_id();