• I have a page separated into multiple sections and multiple divs.
    I want each div to contain a post from my WordPress backend I can edit If i need to.

    I don’t know php or code much to be honest, so I looked up on the Worpress documentation how I could get this done.

    I tried their tips but the page is not coming up.

    Can anyone assist?

    the code for my index.php is attached below, I don’t know what I’m doing wrong.

    <?php get_header(); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
    <html>
    <head>
    <meta name="generator" content="HTML Tidy for Linux (vers 25 March 2009), see www.w3.org">
    <title></title>
    </head>
    <body>
    <div class="gal_1">// The Query <?php $query = new WP_Query( 'category_name=1' );
    
    // The Loop
    while ( $query1->have_posts() ) {
            $query1->the_post();
    }
    
    /* Restore original Post Data
     * NB: Because we are using new WP_Query we aren't stomping on the
     * original $wp_query and it does not need to be reset with
     * wp_reset_query(). We just need to set the post data back up with
     * wp_reset_postdata().
     */
    wp_reset_postdata(); ?></div>
    <div class="strip"></div>
    <div class="content">/* The 2nd Query (without global var) */ <?php $query = new WP_Query( 'category_name=2' );
    
    // The 2nd Loop
    while( $query2->have_posts() ) {
            $query2->next_post();
            echo '<li>' . get_the_title( $query2->post->ID ) . '</li>';
    }
    
    // Restore original Post Data
    wp_reset_postdata(); ?></div>
    <div class="strip"></div>
    <div class="hero"><img src="img/hero.jpg" width="100%" height="651" alt=""></div>
    <div class="strip"></div>
    <div class="container_w content_2">/* The 3rd Query (without global var) */ <?php $query = new WP_Query( 'category_name=3' );
    
    // The 3rd Loop
    while( $query2->have_posts() ) {
            $query2->next_post();
            echo '<li>' . get_the_title( $query2->post->ID ) . '</li>';
    }
    
    // Restore original Post Data
    wp_reset_postdata(); ?></div>
    <?php get_footer(); ?>
    </body>
    </html>

The topic ‘WP_Query Multi Post not working’ is closed to new replies.