【发布时间】:2016-03-09 15:08:42
【问题描述】:
下面的代码是一个 WordPress 书店网站,它在每个书页上输出关于作者的简介,从相应的作者页面中提取内容。它在大多数情况下都可以正常工作,除非有多个作者,它只显示一个作者(有时不显示主要作者)。
有没有办法修改它,如果有多个作者,它会显示所有作者的简介?
谢谢!
<?php if ( is_single() ) { ?>
<div class="featured-author">
<div class="widget widget_lpcode">
<h2 class="widget-title">About the Author</h2>
<div class="textwidget">
<?php
$authors = array();
$parents = array(
'Author' => 35
);
$categories = get_the_terms( $post->ID, 'product_cat' );
foreach( $parents as $parent_name => $parent_id ):
foreach( $categories as $category ):
if( $parent_id == $category->parent ):
$authors[] = $category->slug;
endif;
endforeach;
endforeach;
$custom_query = new WP_Query( array( 'post_type' => 'authors','post_name__in' => $authors,'posts_per_page' => '-1' ) );
if($custom_query->have_posts()) :
while($custom_query->have_posts()) :
$custom_query->the_post();
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_post_thumbnail('thumbnail'); ?></a>
<header class="entry-header">
<h1 class="entry-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
</header>
<div class="entry-content">
<p><?php get_the_content_limit(115, ''); ?></p>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>" class="more">More</a></p>
</div>
</article>
<?php
endwhile;
else:
?>
Not Found.
<?php
endif;
?>
</div>
</div>
</div>
【问题讨论】:
标签: php wordpress custom-post-type