Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WordPress:帮助简化if elseif列表循环_Wordpress_Loops_If Statement - Fatal编程技术网

WordPress:帮助简化if elseif列表循环

WordPress:帮助简化if elseif列表循环,wordpress,loops,if-statement,Wordpress,Loops,If Statement,我是WordPress主题的新手,希望你能帮我简化这个循环。最大的问题是不需要将列表项重复两次,尽管我也欢迎其他改进建议 我感谢所有的帮助,并将标记正确的答案。多谢各位 <ul> <?php if (is_page('about')) { ;?> <?php query_posts("post_type=page&post_parent=6"); if ( have_posts() ) : while ( hav

我是WordPress主题的新手,希望你能帮我简化这个循环。最大的问题是不需要将列表项重复两次,尽管我也欢迎其他改进建议

我感谢所有的帮助,并将标记正确的答案。多谢各位

<ul>

<?php if (is_page('about')) { ;?>

    <?php
        query_posts("post_type=page&post_parent=6"); 
        if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>

        <li>blah blah blah</li>

    <?php endwhile; else: ?>
      <p>Some error message or similar.</p>
    <?php endif; ?>

<?php } elseif (is_page('history')) { ;?>

    <?php
        query_posts("post_type=page&post_parent=4"); 
        if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>

        <li>blah blah blah</li>

    <?php endwhile; else: ?>
      <p>Some error message or similar.</p>
    <?php endif; ?>

<?php } ?>

</ul>
  • 废话废话
  • 一些错误消息或类似消息

  • 废话废话
  • 一些错误消息或类似消息


谢谢你,雷曼。这确实需要一些调整才能开始工作:

<?php 
if (is_page('about')) { 
        query_posts("post_type=page&post_parent=6"); 
} elseif (is_page('history')) {
        query_posts("post_type=page&post_parent=4"); 
}

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

        <li>blah blah blah</li>

    <?php endwhile; else: ?>
      <p>Some error message or similar.</p>
    <?php endif; ?>

</ul>

  • 废话废话
  • 一些错误消息或类似消息

    • 废话废话
    • 一些错误消息或类似消息

    <ul>
    
    <?php 
    if (is_page('about')) { 
            query_posts("post_type=page&post_parent=6"); 
    } elseif (is_page('history')) {
            query_posts("post_type=page&post_parent=4"); 
    }
    
    if ( have_posts() ) { while ( have_posts() ) : the_post();
        ?>
    
            <li>blah blah blah</li>
    
        <?php endwhile; else: ?>
          <p>Some error message or similar.</p>
    
    
    </ul>