I know, similar questions have been asked in many ways, but I simply cannot find any answer.
I have a page (book) with 4 tabs:
– Summary (=page content)
– Look inside
– Buy it
The tab “Reviews” should be a custom loop of specific posts (book reviews) (using post type, and order by custom field: publication date)
The reason it has to be a page template and not category template is that the site owner must have frontend access to write some content, without messing with the rest, or having to work directly on a template file.
What I have come up with so far does work, but shows the custom loop on top of page instead of inside the tab!
(Note: I use shortcode for tabs, so the first [tab] part comes from the page content and needs to be finished by the template. That part is not the problem)
This is my code:
get_header(); ?> <?php while ( have_posts() ) : the_post(); ?> <h1 class="page-title"><?php the_title(); ?></h1> <?php global $post; // get post ID for reuse after custom loop $tmp_post = $post; ?> <?php // get content from frontend $content = get_the_content() $content .= '[/tab] [tab title="Look inside" id="td2"] link to Google docs file [/tab] [tab title="Reviews" id="3"]' <?php // THIS IS THE PROBLEM PART $query = array ( 'post_type' => 'reviews', 'meta_query' => array( array('key' => 'wpcf-book-review', 'value' => '1', 'compare' => '=' ) ), 'order-by' => 'meta-value-num', 'meta-key' => 'wpcf-pub-data', 'order' =>'ASC' ); $my_query = new WP_Query($query); if ( $my_query->have_posts() ) : while ( $my_query->have_posts()) : $my_query->the_post(); $loopcontent .= get_template_part( 'includes/loop-review'); endwhile; endif; $content .= $loopcontent . '[/tab] [tab title="Buy it" id="t4"] Links to bookstores [/tab] [/tabgroup]'; echo apply_filters('the_content',$content); //reset post ID to main page $post = $tmp_post; wp_reset_postdata(); // all the rest: comment form, sidebar, etc.
This code does concatenate nicely the different tab bits from page content and rest of the template, only the custom loop does not remain within the tab, but shows up right after the_title (from page).
I have tried the Blog-in-blog plugin, and it does indeed put the custom loop inside the correct tab!
Just that it does not allow to do advanced queries and display order the way I want it (and my PHP knowledge is not that advanced that I can mess around with the code there).
Any help is greatly appreciated to solve that mystery why my custom loop jumps to the top of the page!
Thank you in advance!
- The topic ‘Custom loop on page – comes up on top of page’ is closed to new replies.