【问题标题】:My WordPress loop for posts fails我的 WordPress 帖子循环失败
【发布时间】:2014-01-21 17:44:17
【问题描述】:

我使用该代码每 3 个帖子在我的主页上发布一个广告,但该广告不是出现在第 1 个帖子后面,而且它似乎根本无法识别循环

<div id="mason-layout" class="transitions-enabled fluid">
<?php /* Start the Loop */ ?>

<?php while ( have_posts() ) : the_post(); ?>

    <?php get_template_part( 'content', 'blog' ); ?>
<?php if ($i == 3) { ?> ADHERE <?php } ?>
<?php $i++; ?>
<?php endwhile; ?>

有什么想法吗? 谢谢

【问题讨论】:

  • 对不起,代码上面也有这两行

标签: wordpress loops if-statement while-loop adsense


【解决方案1】:

您缺少循环的一部分。

<?php if (have_posts()): while (have_posts()) : the_post(); ?>

编辑:如果您想将 if 语句分成多行,您可能需要使用不同的语法。例如:

if ( have_posts() ) {
    while ( have_posts() ) {
        the_post(); 
        //
        // Post Content here
        //
    } // end while
} // end if

推荐阅读:http://codex.wordpress.org/The_Loop

【讨论】:

  • 我知道,我复制粘贴错了,我错过了 2 行
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-25
  • 2014-07-28
  • 1970-01-01
  • 2017-04-30
相关资源
最近更新 更多