我想循环浏览wordpress中的文章,但是我的循环做了一些错误,因为我得到了一个错误,不知道如何修复它。这是循环:
<?php if ($wp_query->have_posts()) : global $wp_query; $count = $wp_query->found_posts; ?>
<?php while ( $wp_query->have_posts()) : $wp_query->the_post(); ?>
<li> <?php echo get_the_title() ?></li>
<?php endwhile; ?>
<?php endif; ?>我犯了个错误
页面不工作了 superselma.dev目前无法处理此请求。HTTP错误500
更新的
当我这样做的时候:
<?php if ($wp_query->have_posts()) :?>
<?php if ($wp_query->have_posts()) : global $wp_query; $count = $wp_query->found_posts; ?>
<?php while ( $wp_query->have_posts()) : $wp_query->the_post(); ?>
<li> <?php echo get_the_title() ?></li>
<?php endwhile; ?>
<?php endif; ?>那它就起作用了。所以,问题就在这一行上:
<?php if ($wp_query->have_posts()) : global $wp_query; $count = $wp_query->found_posts; ?>这是页面的完整代码:
<?php if ($wp_query->have_posts()) :?>
<?php if ($wp_query->have_posts()) : global $wp_query; $count = $wp_query->found_posts; ?>
<?php while ( $wp_query->have_posts()) : $wp_query->the_post(); ?>
<li> <?php echo get_the_title() ?></li>
<?php endwhile; ?>
<?php endif; ?>
<?php if ($count > $per_page) :?>
<div id="target-area"></div>
<div class="small-centered small-10 medium-6 columns">
<a id="get-more" class="sfk-btn button expand" href="javascript:getMore(<?php echo $cat_id; ?>, <?php echo $per_page; ?>, <?php echo $per_page; ?>)"><span>Klikk for mer</span></a>
</div>
<?php endif; ?>
<?php else : ?>
<article id="post-0" class="post no-results not-found">
<header class="entry-header">
<h1 class="entry-title"><?php _e( 'Ikke flere artikler', 'twentyeleven' ); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<p><?php _e( 'Beklager, men ingen poster var funnet for dette arkivet.', 'twentyeleven' ); ?></p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
</article><!-- #post-0 -->
<?php endif; ?>发布于 2017-02-16 10:01:22
声明(或如果存在删除)全局$wp_query;在if语句和删除endif之前;在div class=“小中心小-10中-6列”之后
发布于 2017-02-16 10:05:52
从代码中删除全局$wp_query;。它将开始打印标题。
发布于 2017-02-16 10:11:56
首先,您能否查看php错误日志,如果没有定义它在php.ini中配置它有很大帮助,也可以将wordpress设置为调试模式。
http://php.net/manual/en/errorfunc.configuration.php#ini.error-log
https://stackoverflow.com/questions/42270349
复制相似问题