【发布时间】:2013-09-11 15:13:52
【问题描述】:
所以我一直在构建 author.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();
?>
如果有问题的用户有他/她的名字的任何帖子,那很好。 但是,当他们的帖子为零时,个人资料页面在应该有内容的地方出现空白。
我该如何克服这个问题?
仅供参考,完整的 author.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; ?>
`
【问题讨论】:
-
有一个插件可以解决这个问题,但它在我的网站上不起作用。代码运行...
if (!function_exists('show_authors_without_posts')) { function show_authors_without_posts($template) { global $wp_query; if( !is_author() && get_query_var('author') && (0 == $wp_query->posts->post) ) { // debug // echo 'Overwrite default 404 template...'; return get_author_template(); } return $template; } add_filter('404_template', 'show_authors_without_posts'); }这有什么问题需要更改才能为我工作吗?
标签: php wordpress profile author