所以我一直在构建作者.php页面来显示用户配置文件。
这依赖于顶部的"如果(have_posts() ) :",其中 - 仅供参考 - 我也有...
<?php
/* Queue the first post, that way we know
* what author we're dealing with (if that is the case).
*
* We reset this later so we can run the loop
* properly with a call to rewind_posts().
*/
the_post();
?>
<?php
/* Since we called the_post() above, we need to
* rewind the loop back to the beginning that way
* we can run the loop properly, in full.
*/
rewind_posts();
?>
如果相关用户以他/她的名义发布任何帖子,那很好。但是,当他们没有帖子时,个人资料页面会在应该有内容的地方出现空白。
我怎样才能克服这个问题?
仅供参考,完整作者.php是...
'
<?php if ( have_posts() ) : ?>
<?php
/* Queue the first post, that way we know
* what author we're dealing with (if that is the case).
*
* We reset this later so we can run the loop
* properly with a call to rewind_posts().
*/
the_post();
?>
<?php
/* Since we called the_post() above, we need to
* rewind the loop back to the beginning that way
* we can run the loop properly, in full.
*/
rewind_posts();
?>
<?php
/* Get Extra User Fields*/
$values_by_name = array( // Assign defaults to all CIMY fields
'TITLEJOB' => '',
'TITLESECONDARY' => '',
'COMPANY' => '',
);
$values = get_cimyFieldValue($author, false);
if ($values) {
foreach ($values as $value) {
$values_by_name[$value['NAME']] = cimy_uef_sanitize_content($value['VALUE']);
}
}
?>
<h1><?php the_author(); ?></h1>
<?php
if(!empty($values_by_name['COMPANY'])) {
echo '<p>Company: '.$values_by_name['COMPANY'].'</p>';
}
if(!empty($values_by_name['TITLEJOB'])) {
echo '<p>Title: '.$values_by_name['TITLEJOB'].'</p>';
if(!empty($values_by_name['TITLESECONDARY'])) {
echo '<p>Secondary: '.$values_by_name['TITLESECONDARY'].'</p>';
}
}
?>
<?php
?>
<p><?php echo get_avatar( get_the_author_meta( 'user_email' )); ?></p>
<p>URL: <a href="<?php the_author_meta( 'user_url' ); ?>"><?php the_author_meta( 'user_url' ); ?></a></p>
<p>Description: <?php echo nl2br(get_the_author_meta( 'description' )); ?></p>
<h4>Posts: <?php the_author_posts(); ?></h4>
<?php /* Start the Loop */ ?>
<ul>
<?php while ( have_posts() ) : the_post(); ?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
</ul>
<h4>Topics</h4>
<ul>
<li>Topic</li>
<li>Topic</li>
<li>Topic</li>
</ul>
<h4>Companies</h4>
<ul>
<li>Company</li>
<li>Company</li>
<li>Company</li>
</ul>
<?php endif; ?>
`
您不能自己查询吗?
haveno_posts{
If Posts = 0 then return true?
}
<?php if ( have_posts() ) : ?>
将
<?php if ( have_posts() || haveno_posts() ) : ?>
或者:
http://wordpress.org/plugins/show-authors-without-posts/admin/
https://wordpress.stackexchange.com/questions/41078/show-author-archive-pages-for-authors-with-no-posts
您将整页内容包装在条件中:
if ( have_posts() ) :
按理说,如果用户没有帖子,它会跳到底部并且什么都不显示......