我创建了自己的自定义帖子类型(文章)。现在,所有文章的作者都应显示在概述页面上。如果单击名称,将进入相应的作者个人资料。
但是,如果某个作者写了三篇文章,那么他将在概述页面上显示三遍。有谁知道我该如何解决这个问题?非常感谢你。
<?php get_header();
$args = (array(
'post_type' => 'article',
'orderby' => 'name',
'order' => 'ASC',
));
$myquery = new WP_Query($args);
?>
<?php
// Start the loop.
if ($myquery->have_posts()) :
while ($myquery->have_posts()) :
$myquery->the_post();
$img = get_the_author_meta('image-author');
echo wp_get_attachment_image($img, 'image-author'); ?>
<?php echo the_author_posts_link($args); ?>
<?php
endwhile;
endif;
?>
<?php get_footer(); ?>
参考方案
您可以尝试以下代码:
if ($myquery->have_posts()) :
$authors_ids = [];
while ($myquery->have_posts()) :
$myquery->the_post();
$img = get_the_author_meta('image-author');
$author_id = get_the_author_meta('ID');
if (in_array($author_id, $authors_ids)) {
continue;
}
$authors_ids[] = $author_id;
echo wp_get_attachment_image($img, 'image-author');
?>
<?php echo the_author_posts_link($args); ?>
<?php
endwhile;
endif;
PHP:对数组排序 - php请如何排序以下数组Array ( 'ben' => 1.0, 'ken' => 2.0, 'sam' => 1.5 ) 至Array ( 'ken' => 2.0, 'sam' => 1.5, 'ben' =&…
PHP strtotime困境 - php有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00…
PHP-全局变量的性能和内存问题 - php假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…
php Singleton类实例将在多个会话中保留吗? - php举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…
php-casperjs获取内部文本 - php我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…