Hi I'm currently working on this project
I want to create 2 style post one for the first 2 post and another style for the last 4 post.
Here is the code I'm using.
<?php
$args = array( 'posts_per_page' => 2, 'category' => 5 );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
// content of the first 2 post here //
<?php endforeach; wp_reset_postdata();?>
<?php
$args = array( 'posts_per_page' => 4, 'category' => 5,'offset' => 2 );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
// content of the last 4 post here //
<?php endforeach; wp_reset_postdata();?>
I searched and I knew that by this way the page pagination will not work. But I only know a few basic in wordpress and php coding.
Can anyone help me solve this problem please?
Here is the design I made in PSD
<?php $args = array( 'posts_per_page' => 2, 'category' => 5 );
$myposts = get_posts( $args );
$count = 1;
if($myposts->have_posts()): while($myposts->have_post): $myposts->the post();
if($count < 3 ){
//content and style of the first two post
$count++;
}
else{
//content and style of the rest of the post
$count++;
}
endwhile;
endif;
?>
This should do the trick.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.