当用户未登录时,为什么the_author应在第一页返回一个空字符串,但返回作者姓名的原因与通过AJAX加载更多帖子时的情况相同? 循环在两种情况下都是相同的。 请帮我解决这个问题,因为我很无能,我需要尽快修复以启动我的网站。未登录时the_author为空
这里是整个的index.php:
<?php
get_header();
get_sidebar();
?>
<!-- MAIN DIV -->
<div id='content_and_floater'>
<?php get_template_part('social_floater'); ?>
<div id='content'>
<?php get_template_part('loop'); ?>
</div>
</div>
<?php get_template_part('loader'); ?>
<!-- MAIN DIV -->
<?php
get_footer();
?>
而这里的infinitePaginator如何调用的functions.php环路(当向下滚动至底部或在点击链接加载函数被调用):
function wp_infinitepaginate(){
$loopFile = $_POST['loop_file'];
$paged = $_POST['page_no'];
$posts_per_page = get_option('posts_per_page');
# Load the posts
query_posts(array('paged' => $paged));
get_template_part($loopFile);
exit;
}
您可以在test.nowillnoskill.net上看到该行为。 在单个帖子中它也不工作。我的猜测是query_posts(array('paged'=> $ paged));在查询中改变了一些内容,但我不知道它是什么。 我试图插入setup_postdata($ post);刚好在loop.php中的_post()之后,因为我发现它适用于某人,但它不适合我。
我也打过电话中的index.php循环文件之前插入
query_posts(array('paged' => 1));
,但被证明根本没有文章。
这里是我的loop.php:
<?php while (have_posts()) : the_post() ?>
<!-- POST1 -->
<article class='post'>
<header class='post_header'>
<?php
global $current_user;
$current_user = wp_get_current_user();
if (!empty($current_user)) {
$pid = get_the_id();
$uid = $current_user->ID;
$title = (is_favorite($pid, $uid)) ?
'Remove from favorites' :
'Add to favorites';
$trans = (is_favorite($pid, $uid)) ?
'' :
' transparent';
?>
<div>
<h2>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</h2>
<?php if (is_user_logged_in()) { ?>
<a title='<?php echo $title ?>' class='post_favorite' href='#' alt='fpid=<?php echo $pid ?>uid=<?php echo $uid ?>'>
<span class='symbol<?php echo $trans ?>'>R</span>
</a>
<?php } ?>
</div>
<div class='post_header_div'>
<strong class='post_category'>
<?php echo get_the_category_list(', '); ?>
</strong>
<strong class='post_author'>
<span class='symbol'>U</span>
<?php the_author(); ?>
</strong>
</div>
<div>
<span class='post_author'>
<?php edit_post_link('[edit]'); ?>
</span>
</div>
<?php } ?>
</header>
<figure class='post_image'>
<!--<img src='design/img/flashkick.png' alt='logo' />-->
<?php the_post_thumbnail(); ?>
</figure>
<div class='post_perex'>
<?php the_content('Read more'); ?>
</div>
<div class='space'></div>
<footer class='post_footer'>
<div class='post_footer_top'>
<div class='post_tags'>
<?php the_tags('', '', ''); ?>
</div>
<div class='post_time'>
<time datetime="<?php the_time('Y-m-d'); ?>" pubdate>
<span class='symbol'>P </span>
<?php relative_post_the_date(); ?>
</time>
</div>
</div>
</footer>
<div class='space'></div>
</article>
<?php endwhile; ?>
我添加了循环代码。请看一下。 当我输出var_dump($ posts);我得到[“post_author”] =>字符串(1)“1” –
我得到相同的输出上的帖子,另外加载了AJAX,但他们正确显示the_author()。 –