admin管理员组文章数量:1130349
im trying to display the post title and post content of posts in diferent divs using a loop to iterate the posts in $the_query, how can achieve this?
<?php $the_query = new WP_Query( 'posts_per_page=4' );?>
the structure should be something like this
<div class="grid">
<div class="main post">
<!--show data of the first post in the array-->
</div>
<div class="nested">
<div class="first post">
<!--show data of the second post in the array-->
</div>
<div class="second post">
<!--show data of the third post in the array-->
</div>
<div class="third post">
<!--show data of the fourth post in the array-->
</div>
</div> <!--end nested-->
</div> <!--end grid-->
im trying to display the post title and post content of posts in diferent divs using a loop to iterate the posts in $the_query, how can achieve this?
<?php $the_query = new WP_Query( 'posts_per_page=4' );?>
the structure should be something like this
<div class="grid">
<div class="main post">
<!--show data of the first post in the array-->
</div>
<div class="nested">
<div class="first post">
<!--show data of the second post in the array-->
</div>
<div class="second post">
<!--show data of the third post in the array-->
</div>
<div class="third post">
<!--show data of the fourth post in the array-->
</div>
</div> <!--end nested-->
</div> <!--end grid-->
Share
Improve this question
asked Nov 26, 2018 at 19:04
TraukoTrauko
251 silver badge6 bronze badges
1 Answer
Reset to default 2PHP loops are loops - you can control them ;)
<?php
$the_query = new WP_Query( array('posts_per_page' => 4) );
if ( $the_query->have_posts() ) :
$the_query->the_post();
?>
<div class="grid">
<div class="main post">
<!--show data of the first post in the array-->
<?php the_title(); ?>
<?php the_content(); ?>
</div>
<div class="nested">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="post">
<!--show data of next post in the array-->
<?php the_title(); ?>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
</div> <!--end nested-->
</div> <!--end grid-->
<?php endif; ?>
im trying to display the post title and post content of posts in diferent divs using a loop to iterate the posts in $the_query, how can achieve this?
<?php $the_query = new WP_Query( 'posts_per_page=4' );?>
the structure should be something like this
<div class="grid">
<div class="main post">
<!--show data of the first post in the array-->
</div>
<div class="nested">
<div class="first post">
<!--show data of the second post in the array-->
</div>
<div class="second post">
<!--show data of the third post in the array-->
</div>
<div class="third post">
<!--show data of the fourth post in the array-->
</div>
</div> <!--end nested-->
</div> <!--end grid-->
im trying to display the post title and post content of posts in diferent divs using a loop to iterate the posts in $the_query, how can achieve this?
<?php $the_query = new WP_Query( 'posts_per_page=4' );?>
the structure should be something like this
<div class="grid">
<div class="main post">
<!--show data of the first post in the array-->
</div>
<div class="nested">
<div class="first post">
<!--show data of the second post in the array-->
</div>
<div class="second post">
<!--show data of the third post in the array-->
</div>
<div class="third post">
<!--show data of the fourth post in the array-->
</div>
</div> <!--end nested-->
</div> <!--end grid-->
Share
Improve this question
asked Nov 26, 2018 at 19:04
TraukoTrauko
251 silver badge6 bronze badges
1 Answer
Reset to default 2PHP loops are loops - you can control them ;)
<?php
$the_query = new WP_Query( array('posts_per_page' => 4) );
if ( $the_query->have_posts() ) :
$the_query->the_post();
?>
<div class="grid">
<div class="main post">
<!--show data of the first post in the array-->
<?php the_title(); ?>
<?php the_content(); ?>
</div>
<div class="nested">
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="post">
<!--show data of next post in the array-->
<?php the_title(); ?>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
</div> <!--end nested-->
</div> <!--end grid-->
<?php endif; ?>
本文标签: wp queryShow post content and title in diferent divs using WPQuery using a loop
版权声明:本文标题:wp query - Show post content and title in diferent divs using WP_Query using a loop 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749150689a2323763.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论