As in WordPress to display the first post separately from the whole?

Hi Toaster!

I already absolutely a head broke and desperate, trying to solve the thing conceived. There is a loop that displays the normal posts. The loop is wrapped in a div of its parent. Inside the output cycle has its own markup.

I want to take the first post and publish it over the entire cycle (somewhere over the div-parent cycle). So laid out.

Schematic representation:


How to be? I know that the cycles cannot be duplicated, but the two on the page may exist. I know that the last post can be checked as follows:

<?php if (($wp_query--->current_post +1) == ($wp_query->post_count)) {
echo 'This is the last post';
} ?>
June 14th 19 at 20:13
5 answers
June 14th 19 at 20:15
Works for me so
<?php $first_post = get_posts( array(
 'numberposts' =--> 1,
 'cat' => '-3792',
 'tag__not_in' => '3867',
 'post__in' => get_option( 'sticky_posts' ),
)); ?> 

<?php $num = 1; ?> 

<?php foreach( $first_post as $post ) : setup_postdata( $post ); ?>

<article id="post-<?php the_ID(); ?>" <?php post_class( pg_get_posts_classes( $num ) ); ?>> 
 <div class="inner">
 <div class="caption">
 <div class="thumbnail">
 <a href="<?php the_permalink() ?>">
 if ( has_post_thumbnail() ) {
 the_post_thumbnail( 'pg-main' ); 
 } else {
 pg_first_attachment_image( $post--->ID, 'pg-main' );
 <?php pg_entry_meta( $post--->ID ); ?> 
 <h3 class="entry-title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
 <?php the_excerpt(); ?>

<?php endforeach; ?>

<?php query_posts( array(
 'posts_per_page' =--> 8,
 'cat' => '-3792',
 'post__not_in' => array( $first_post[0]->ID ),
 'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 ),

<?php $num = 2; ?> 

<?php while (have_posts()) : the_post(); ?> 
<article id="post-<?php the_ID(); ?>" <?php post_class( pg_get_posts_classes( $num ) ); ?>> 
 <?php get_template_part( 'content', get_post_format() ); ?> 
<?php $num++; ?>
<?php endwhile; ?> 
<?php wp_reset_query(); ?>
June 14th 19 at 20:17
Not much the expert on WP, but the documentation is all there - wp get recent posts, no?
<h2>Recent Posts</h2>
the <ul>
 $args = array( 'numberposts' =--> '1' );
 $recent_posts = wp_get_recent_posts( $args );
 foreach( $recent_posts as $recent ){
 echo '<li><a href="' . get_permalink($recent[" id"]) . '">' . $recent["post_title"].'</a> </li> ';

ps why of the overall cycle do not take the first post, which will go into the hat, and the other in the net? Why a separate query to do?
So you suggest to make one page two cycles. In the first loop displays only the first (and only post), do the layout exactly as it should.

Further, the second cycle already in the grid but not showing the first post.
Understand you correctly? This is the normal approach? Or is there some more subtle solution? - nikita.Stracke commented on June 14th 19 at 20:20
I just showed how to get the first post.
I would do one query (sobno code Above). Would receive $results (array) of N positions . And was being parsed it. The first is a hat, the other in the neighboring unit standard cycle. Receive one request, one cycle.
But it is possible and 2, if power(it's an extra load on the server). Sobsno it and there are two approaches in business. Quickly scatter the money - by capacity to the server or to alter the queries to waste time on a solution. the choice is yours. - sonia20 commented on June 14th 19 at 20:23
June 14th 19 at 20:19
Do not understand why a separate request to do so.
In extreme cases, while the meter stick and the first post display differently.
June 14th 19 at 20:21
And why don't you just stilisierte the first post via CSS?
Alas, I have a task more difficult than highlighting through styles. Cited the example code in the comments below. - nikita.Stracke commented on June 14th 19 at 20:24
June 14th 19 at 20:23
Sucks described the idea. I'll try option # 2 with the example code. There is here, already made up:

<?php get_header(); ?>

→ Here you need to withdraw the first post. ←

<div class="grid-wrap">
 <div class="masogridnry">

↓ Standard output of posts without the latter, it needs to be at the top. ↓

 <?php if( have_posts() ): while( have_posts() ): the_post(); ?>
 <a href="<?php the_permalink(); ?>" class="link-<?php the_ID(); ?>">
 <div class="post">
 <h1><?php the_title(); ?></h1>
 <?php endwhile; ?>

 <?php else: ?>
 <p>Nothing, which is strange.</p>
 <?php endif; wp_reset_query(); ?>

 </div><!-- /.masonry -->
</div><!-- /.grid -->

<?php get_footer(); ?>

Text and arrows pointed is where you need to pull in one post. It turns out you need to do two cycles like suggests (if I comment and sample code understand correctly)? Where to approach this problem?

Find more questions by tags WordPress