BuddyBoss Home – Web Support Forums Solutions Social Blogger Add custom loop to homepage =

Tagged: 

Viewing 3 posts - 1 through 3 (of 3 total)
  • Question

    #58900
    @stackstreetnew

    I’ve copied the homepage.php template into my childtheme and its loading fine.

    I’m trying to add a custom loop to the template to display posts (with the tag ‘home’) and its not working, just timing out the site.

    I used this loop in numerous other themes, so im wondering whats causing the timeout.

    <?php

    // BETTER
    $query = array (
    ‘post_type’ => ‘post’,
    ‘post_status’ => ‘publish’,
    ‘order’ => ‘desc’,
    ‘tag’ => ‘home’

    );

    $queryObject = new WP_Query($query);
    if ($queryObject->have_posts()) {
    while ($queryObject->have_posts()) {

    echo ‘<article class=”post entry”>’;
    echo ‘‘; // Original Grid
    echo get_the_post_thumbnail( $post->ID, ‘thumbnail’, array( ‘class’ => ‘alignright post-image entry-image’ ) );
    echo ‘
    ‘;
    echo ‘<header class=”entry-header”><h2 class=”entry-title” id=”hmes” itemprop=”headline”> ‘ . get_the_title() . ‘ </h2></header>’; // show the title
    echo ‘<footer class=”entry-footer”>’;
    echo ‘By <span class=”entry-author” itemprop=”author” itemscope=”itemscope” itemtype=”https://schema.org/Person”>&#8217;;
    echo bp_core_get_userlink(get_the_author_meta(‘ID’));
    echo ‘</span>’;
    echo ‘<p class=”timeb”>’;

    echo ‘<i class=”icon-bookmark”></i>’;

    echo ‘</p>’;

    echo ‘</footer></article>’;
    }
    }

    ?>

    Full code here: http://pastebin.com/EvvN4RZr

    Answers

    #59030
    @stackstreetnew

    Any idea? I need to get this loop functioning as soon as possible, have tried every variation of WP_Query I can think of.

    #59126
    @vapvarun

    Hi @stackstreetnew,
    at present on the template file you are using two loops
    it will be better you use

    
    <?php wp_reset_postdata(); ?>
    

    after end of first loop
    wp_reset_postdata() – used immediately after every custom WP_Query()
    wp_reset_query() – used immediately after every loop using query_posts()
    Regards

Viewing 3 posts - 1 through 3 (of 3 total)
  • The question ‘Add custom loop to homepage =’ is closed to new replies.