WordPress.org

Ready to get started?Download WordPress

Forums

Conditional for 'if page 1 of post'? (7 posts)

  1. timwheatley
    Member
    Posted 5 years ago #

    Hi guys,

    I want something to display in single.php only when the visitor is viewing page 1, ie:
    permalink/
    or
    permalink/1

    I don't want it to show when they're viewing permalink/2

    I have a conditional setup right now that when I have an image url in a particular custom field, it displays a Java panoramic. But, I only want that on page 1, not on page 2, 3 etc like it is here:
    http://timwheatley.org/www/2008/08/28/city-of-lincoln-panoramicphotosphoto-gallery/3

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    This should do the trick:

    $paged = get_query_var('paged');
    if ($paged < 2) {
    // you're on page 1, put your code here
    }
  3. timwheatley
    Member
    Posted 5 years ago #

    Thanks!

    I tried to put it into single.php but the panorama shows on all pages. Here's my code:
    <?php
    $paged = get_query_var('paged');
    if ($paged < 2) { ?>

    <?php if ( get_post_meta($post->ID, 'panorama_url', true) ) { ?><center>
    <applet archive="http://timwheatley.org/global/ptviewer.jar" code=ptviewer.class width=508 height=300 alt="Please install the Java Virtual Machine plug-in from www.java.com."><param name=file value="<?php echo get_post_meta($post->ID, "panorama_url", $single = true); ?>"></applet></center><div id="footer"><center>Click on the image and move your mouse to look around.<?php if ( get_post_meta($post->ID, 'panorama_size', true) ) { ?> Size: <?php echo get_post_meta($post->ID, "panorama_size", $single = true); ?><?php } ?>
    You may also use the - and + keys to zoom in and out.</center></div>
    <?php } ?>

    <?php } ?>

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    Try "page" instead of "paged". See if that works.

    Could be a WordPress bug there. I'm investigating.

  5. timwheatley
    Member
    Posted 5 years ago #

    That works. :)

  6. timwheatley
    Member
    Posted 5 years ago #

    Ah, one thing. It replaces the whole body of the posts page 1, not just the section I put the code around?

  7. Samuel Wood (Otto)
    Tech Ninja
    Posted 5 years ago #

    I have no idea there. Likely you put the brackets around the wrong piece of code. The code I gave you does nothing at all, replaces nothing at all.

Topic Closed

This topic has been closed to new replies.

About this Topic