Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.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 如何在同一循环中循环浏览自定义帖子_Php_Wordpress - Fatal编程技术网

Php 如何在同一循环中循环浏览自定义帖子

Php 如何在同一循环中循环浏览自定义帖子,php,wordpress,Php,Wordpress,我是PHP新手。所以请容忍我。在WordPress主题中,我创建了一个自定义帖子类型(团队),现在我想在一个分区中显示3个帖子标题,后面是3个帖子(在不同分区中)的内容,然后对每组3个帖子重复此操作,直到查询结束 我的HTML看起来像这样,但我不知道如何组装PHP。因此,任何帮助都将不胜感激: <div class="section-wrapper"> <div class="member-row row-1"> <div class="te

我是PHP新手。所以请容忍我。在WordPress主题中,我创建了一个自定义帖子类型(团队),现在我想在一个分区中显示3个帖子标题,后面是3个帖子(在不同分区中)的内容,然后对每组3个帖子重复此操作,直到查询结束

我的HTML看起来像这样,但我不知道如何组装PHP。因此,任何帮助都将不胜感激:

<div class="section-wrapper">
    <div class="member-row row-1">
        <div class="team-member member-1">
        <h2><?php the_title(); ?></h2>
        </div>
        <div class="team-member member-2">
        <h2><?php the_title(); ?></h2>
        </div>
        <div class="team-member member-3">
        <h2><?php the_title(); ?></h2>
        </div>
    </div>
    <div class="summary summary-1">
        <?php 
        // display the_content() of each of the 3 posts I just queried
        the_content(); 
        ?>
    </div>
</div>
<div class="section-wrapper">
    <div class="member-row row-2">
        <div class="team-member member-4">
        <h2><?php the_title(); ?></h2>
        </div>
        <div class="team-member member-5">
        <h2><?php the_title(); ?></h2>
        </div>
        <div class="team-member member-6">
        <h2><?php the_title(); ?></h2>
        </div>
    </div>
    <div class="summary summary-2">
        <?php 
        // display the_content() of each of the 3 posts I just queried
        the_content(); 
        ?>
    </div>
</div>

我想尝试一种更简单的html,但如果您想使用它,可以使用此代码

 <div class="section-wrapper">
<?php
// WP_Query arguments
$args = array (
    'post_type'              => 'team',
    // choose other differentiating parameter, for example tag 
    'tag'                     => 'main'
);

// The Query
$query = new WP_Query( $args );

// The loop
if( $query->have_posts() ): while( $query->have_posts()): $query->the_post(); 
?>
<div class="member-row row-1 <?php post_class(); ?>">
    <div class="team-member member-1">
    <h2><?php the_title(); ?></h2>
    </div>
</div>
<?php

endwhile; endif;

// Restore original Post Data
wp_reset_postdata();

?>

<?php
// WP_Query arguments
$args = array (
    'post_type'              => 'team',
    // choose other differentiating parameter, for example tag 
    'tag'                     => 'main'
);

// The Query
$query = new WP_Query( $args );

// The loop
if( $query->have_posts() ): while( $query->have_posts()): $query->the_post(); 
?>


<div class="summary <?php post_class() ?>">
    <?php 
    // display the_content() of each of the 3 posts I just queried
    the_content(); 
    ?>
</div>

<?php

endwhile; endif;

// Restore original Post Data
wp_reset_postdata();

?>
</div>


<div class="section-wrapper">
<?php
// WP_Query arguments
$args = array (
    'post_type'              => 'team',
    // choose other differentiating parameter, for example tag 
    'tag'                     => 'seconday'
);

// The Query
$query = new WP_Query( $args );

// The loop
if( $query->have_posts() ): while( $query->have_posts()): $query->the_post(); 
?>
<div class="member-row row-1 <?php post_class(); ?>">
    <div class="team-member member-1">
    <h2><?php the_title(); ?></h2>
    </div>
</div>
<?php

endwhile; endif;

// Restore original Post Data
wp_reset_postdata();

?>

<?php
// WP_Query arguments
$args = array (
    'post_type'              => 'team',
    // choose other differentiating parameter, for example tag 
    'tag'                     => 'secondary'
);

// The Query
$query = new WP_Query( $args );

// The loop
if( $query->have_posts() ): while( $query->have_posts()): $query->the_post(); 
?>


<div class="summary <?php post_class() ?>">
    <?php 
    // display the_content() of each of the 3 posts I just queried
    the_content(); 
    ?>
</div>

<?php

endwhile; endif;

// Restore original Post Data
wp_reset_postdata();

?>
</div>


我会尝试一个更简单的html,但是如果你想使用它,你可以使用下面的代码

 <div class="section-wrapper">
<?php
// WP_Query arguments
$args = array (
    'post_type'              => 'team',
    // choose other differentiating parameter, for example tag 
    'tag'                     => 'main'
);

// The Query
$query = new WP_Query( $args );

// The loop
if( $query->have_posts() ): while( $query->have_posts()): $query->the_post(); 
?>
<div class="member-row row-1 <?php post_class(); ?>">
    <div class="team-member member-1">
    <h2><?php the_title(); ?></h2>
    </div>
</div>
<?php

endwhile; endif;

// Restore original Post Data
wp_reset_postdata();

?>

<?php
// WP_Query arguments
$args = array (
    'post_type'              => 'team',
    // choose other differentiating parameter, for example tag 
    'tag'                     => 'main'
);

// The Query
$query = new WP_Query( $args );

// The loop
if( $query->have_posts() ): while( $query->have_posts()): $query->the_post(); 
?>


<div class="summary <?php post_class() ?>">
    <?php 
    // display the_content() of each of the 3 posts I just queried
    the_content(); 
    ?>
</div>

<?php

endwhile; endif;

// Restore original Post Data
wp_reset_postdata();

?>
</div>


<div class="section-wrapper">
<?php
// WP_Query arguments
$args = array (
    'post_type'              => 'team',
    // choose other differentiating parameter, for example tag 
    'tag'                     => 'seconday'
);

// The Query
$query = new WP_Query( $args );

// The loop
if( $query->have_posts() ): while( $query->have_posts()): $query->the_post(); 
?>
<div class="member-row row-1 <?php post_class(); ?>">
    <div class="team-member member-1">
    <h2><?php the_title(); ?></h2>
    </div>
</div>
<?php

endwhile; endif;

// Restore original Post Data
wp_reset_postdata();

?>

<?php
// WP_Query arguments
$args = array (
    'post_type'              => 'team',
    // choose other differentiating parameter, for example tag 
    'tag'                     => 'secondary'
);

// The Query
$query = new WP_Query( $args );

// The loop
if( $query->have_posts() ): while( $query->have_posts()): $query->the_post(); 
?>


<div class="summary <?php post_class() ?>">
    <?php 
    // display the_content() of each of the 3 posts I just queried
    the_content(); 
    ?>
</div>

<?php

endwhile; endif;

// Restore original Post Data
wp_reset_postdata();

?>
</div>


@我继承了这个()。它在文章中循环,但我不知道如何打破循环,创建我的summary div,然后再次开始循环。这里有一些必要的阅读资料-实际上你应该阅读整个页面的上下文,但特别是关于嵌套循环的部分:@JoshLaBau谢谢!因此,我在当前循环中添加了一个嵌套循环,它似乎正在工作。某种程度上。但是现在,它不再显示与主循环中相同的3项,而是显示不同的3项。我还觉得我在不必要地重复我的质疑论点。下面是我的更新代码:我正在查看您的目标HTML,我认为您真正想要的是有一个WP_查询,但在该循环中,将每个帖子内容的结果保存到一个数组中。然后,每三次迭代,输出summary div和section/member行标记,并销毁包含内容的数组。因此,每个循环中只显示前面三项的摘要内容。@JoshLaBau这是正确的,但我完全不知道如何做。有什么建议吗?谢谢你的帮助。@mdamia我继承了这个()。它在文章中循环,但我不知道如何打破循环,创建我的summary div,然后再次开始循环。这里有一些必要的阅读资料-实际上你应该阅读整个页面的上下文,但特别是关于嵌套循环的部分:@JoshLaBau谢谢!因此,我在当前循环中添加了一个嵌套循环,它似乎正在工作。某种程度上。但是现在,它不再显示与主循环中相同的3项,而是显示不同的3项。我还觉得我在不必要地重复我的质疑论点。下面是我的更新代码:我正在查看您的目标HTML,我认为您真正想要的是有一个WP_查询,但在该循环中,将每个帖子内容的结果保存到一个数组中。然后,每三次迭代,输出summary div和section/member行标记,并销毁包含内容的数组。因此,每个循环中只显示前面三项的摘要内容。@JoshLaBau这是正确的,但我完全不知道如何做。有什么建议吗?谢谢你的帮助。