• rtech

    (@alivemachine)


    I would like the related post thumbnails to show up only on the last page of multi-page posts.

    I thought if ($page == $pages) would work. But I can’t get the $pages or $numpages variable to work. I also noticed $page counts the first page as “0” and then the next pages as “2”, “3”, etc.

    The code below in the singles-loop.php was the closest I could get.

    <div style="margin-top:35px;"><h3>Related Posts:</h3>
    <div style="margin-top:-13px; margin-left:0px;">
    
    <?php
    if ($page != 0) {
    	get_related_posts_thumbnails();
    }
    ?>
    
    </div>
    </div>
Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter rtech

    (@alivemachine)

    btw, here’s my site that I’m trying to do this for:

    audiostateofmind.com

    the global variables are indeed:

    $page

    $numpages

    this example should work:

    <?php if( $page == $numpages ) {
    	get_related_posts_thumbnails();
    } ?>

    if not, try to output the variables to see what values they have;

    <?php echo 'sub-page '.$page.' of '.$numpages.' sub-pages.'; ?>

    Thread Starter rtech

    (@alivemachine)

    Thanks for the help but not much luck with that code.

    Now the related posts are only on the first page, not any pages after that.

    Also, the php echo when on the first page of the post is showing nothing for both page or numpages. The second page is showing “2” for page and nothing for numpages. The third page shows “3” for page but again nothing for numpages.

    These correspond exactly to what I was getting earlier while testing the variables. Page 1 seems to have a $page value of 0 and $numpages is not working for any of the pages.

    Any thoughts?

    it is definitively about multi-paged posts using the <!--nextpage--> tag?

    where is that code in relation to the loop?

    are there any other queries inbetween?

    Thread Starter rtech

    (@alivemachine)

    Definitely using the next page tag. The code is below the page numbers and an <hr>. The related posts are showing up fine and in the right place on the site. Just the $pages doesn’t seem to be working.

    I don’t think there are any queries in between. But not exactly sure what a query is.

    Here’s code copied right from my single-loop.php. Hopefully it’s enough to show where I’m trying to implement the $page if statement.

    <div class="entry-content">
    						<?php the_content(); ?>
    
    						<div style="margin-top:15px; margin-bottom:10px;">
    						<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    
    </div>
    <div style="margin-top:27px;">
    <hr>
    </div>
    
    <div style="margin-top:20px;"><h3>Related Posts:</h3>
    	<div style="margin-top:-13px; margin-left:0px;">
    <?php if( $page == $numpages ) {
    	get_related_posts_thumbnails();
    } ?>
    </div>
    </div>
    
    </div>
    
    <!-- .entry-content -->

    copied right from my single-loop.php

    great information – as this template is probably separated from where the variables are defined, try to add:

    global $page; global $numpages;

    before your code;

    i.e.

    <?php global $page; global $numpages;
    if( $page == $numpages ) {
    	get_related_posts_thumbnails();
    } ?>
    Thread Starter rtech

    (@alivemachine)

    It works! Thanks alot for taking the time to help me out.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘"Related Posts" on last page only of multi-page post’ is closed to new replies.