Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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
Php Wordpress循环;贴子“每页=4”;只显示一个帖子_Php_Wordpress_Loops - Fatal编程技术网

Php Wordpress循环;贴子“每页=4”;只显示一个帖子

Php Wordpress循环;贴子“每页=4”;只显示一个帖子,php,wordpress,loops,Php,Wordpress,Loops,我有一个循环要检查 如果选中了自定义字段(复选框),则 如果后面的循环中有内容 现在我不明白为什么循环总是只显示一个帖子: <?php //check if field has content if(get_field("news_kategorie")): ?> <ul class="page-articles-related">

我有一个循环要检查

  • 如果选中了自定义字段(复选框),则

  • 如果后面的循环中有内容

  • 现在我不明白为什么循环总是只显示一个帖子:

    <?php 
    //check if field has content
    if(get_field("news_kategorie")): ?>
    
    <ul class="page-articles-related">                                                                           
    <?php
        $temp = $wp_query;
        $wp_query= null;
        $wp_query = new WP_Query();
        $wp_query->query('posts_per_page=6&orderby=date&category_name='.implode (',',get_field('news_kategorie'))); ?>
        <?php 
        //check if loop has content
        if ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    
        <li class="relativ">
        <?php the_title(); ?>
        </li>  
    
        <?php else: { ?>
            <?php echo "There is nothing ..."; ?>
        <?php } ?>
    
        <?php endif; ?>
    </ul>
    
    <?php endif; ?>
    
    
    

    除了
    posts\u per_page=6之外,所有内容都正常工作,我总是看到一篇文章,但我想显示六篇文章。

    您当前的代码只打印一篇文章,这应该打印所有六篇文章:

    if ($wp_query->have_posts()) : $wp_query->the_post();
        while ( have_posts() ) 
        {
            ?>
            <li class="relativ">
            <?php the_title(); ?>
            </li>  
    
        <?php
        } // end while
    
    if($wp\u query->have\u posts()):$wp\u query->the\u post();
    while(have_posts())
    {
    ?>
    

  • 因为没有迭代?只有一个if语句..后面没有循环。循环将由“while”或“foreach”语句组成,您目前还没有编程。您当前的代码除了不显示任何内容或单个post之外,无法执行任何其他操作。