• Hi

    I have website using wordpress as a CMS system and I have picture fixed into the template on the left hand side of the page that I assign using a custom field.

    I was wondering, when I use the <!–nextpage–> tag it will create a second page, but obviously the pic on the left is the same as on the first one.

    I was wondering if there was a way around it so I could also assign a second image in my custom fields so when people click on page 2 it switches the picture?

    I know I could embed the pictures in each article as I go along but I want it the way I’ve described above so the template layout stays exactly the same.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter vincepettit

    (@vincepettit)

    Anyone?

    Thread Starter vincepettit

    (@vincepettit)

    So NOBODY has any thoughts or even opinions on this?

    $page = (get_query_var('page')) ? get_query_var('page') : 1;
    if ($page == 1) {
    //do your page 1 image thing
    } elseif ($page == 2) {
    //do your page 2 image thing
    } else {
    //do whatever you need
    }

    Related:
    Pages
    https://justintadlock.com/archives/2007/10/27/wordpress-custom-fields-adding-images-to-posts
    Using Custom Fields
    https://us2.php.net/manual/en/control-structures.elseif.php

    Thread Starter vincepettit

    (@vincepettit)

    Thanks for that, sorry for sounding dumb but how do I implement that with the code I use…

    <?php $thereisimage = get_post_meta($post->ID, image, true);
    if($thereisimage){ ?>
    	<img src="<?php echo get_post_meta($post->ID, image, true); ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"/>
    <?php }else{ ?>
    	<img src="<?php bloginfo('url'); ?>/default.jpg" alt="Default Image" />
    <?php } ?>

    do you want a different image for every post or every page?

    Thread Starter vincepettit

    (@vincepettit)

    different page of the post… for example I have a post that is 5 pages long, I want to use my custom field to put in the image and then have image 1 display on page 1, image 2 on page 2 etc…

    I worked up some quick code so it may be buggy as I haven’t tested it. You’ll have to use the custom fields to set the images by page number.

    <?php
       $thereisimage = get_post_meta($post->ID, image, true);
       $page = (get_query_var('page')) ? get_query_var('page') : 1;
    
       if ($page == 1) { ?>
          <img src="<?php echo get_post_meta($post->ID, image1, true); ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"/>
       <?php } elseif ($page == 2) { ?>
          <img src="<?php echo get_post_meta($post->ID, image2, true); ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"/>
       <?php } elseif { ?>
          <img src="<?php echo get_post_meta($post->ID, image3, true); ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>"/>
       <?php } else { ?>
          <img src="<?php bloginfo('url'); ?>/default.jpg" alt="Default Image" />
    <?php } ?>

    To explain, you set you’re thereisimage variable the the page variable. If the user is on page 1 it displays the image with the image1 key, if page two the image2 key and so on and so forth until it runs out of pages or keys, then it displays the default code.

    Hope this helps.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Different picture on different pages using custom fields?’ is closed to new replies.