Help with the query_post function WordPress

0

I'm trying to make a custom posts in my WordPress theme, however I have a problem. I want to get seven Posts on the main page, my index. But the first post I'll stylise differently from the other six. I am repeating the query_posts (). At first I put it like this:

I'm using this to get the first post.

query_posts ('posts_per_page = 1')
if (have_posts ()): while (have_posts ()): the_post ();

And for the others I'm repeating the code with a different parameter. query_posts ('posts_per_page = 5')
if (have_posts ()): while (have_posts ()): the_post ();

The problem is that the first post is being repeated in both blocks. I wanted to know if you have any parameters that I can use in the second block to make a "jump" start picking up the posts from 2.

    
asked by anonymous 12.06.2018 / 16:32

2 answers

0

I found the solution! Just pass the following parameter in the query_posts () function: query_posts ('showposts = 4 & offset = 1');

    
12.06.2018 / 16:50
0

We do not recommend using the query_posts function. See what's on WordPress documentation :

  

Note that using this method can extend the page load, since the main query is called more than once. In some scenarios it may be worse, doubling the number of unnecessarily executed processes. Although simple to run, the function is also prone to future problems.

The suggestion is to use the WP_Query class or the get_posts . Example of using the WP_Query class:

<?php

    // WP_Query arguments
    $args = array(
    );

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

    // The Loop
    if ( $the_query->have_posts() ) {
        echo '<ul>';
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
            echo '<li>' . get_the_title() . '</li>';
        }
        echo '</ul>';
    } else {
        echo '<p>Nenhum post encontrado</p>'
    }
    /* Restore original Post Data */
    wp_reset_postdata();
    
12.06.2018 / 17:56