BuddyBoss Home – Web › Support Forums › Solutions › Social Blogger › Add custom loop to homepage =
Tagged: custom loop
- This topic has 2 replies, 2 contibutors, and was last updated 8 years, 9 months ago by Anonymous.
Question
February 11, 2016 at 1:33 am #58900@stackstreetnewI’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”>’;
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
February 12, 2016 at 12:44 pm #59030@stackstreetnewAny idea? I need to get this loop functioning as soon as possible, have tried every variation of WP_Query I can think of.
February 13, 2016 at 12:49 pm #59126@
AnonymousHi @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
- The question ‘Add custom loop to homepage =’ is closed to new replies.