I have a post that I would like to split in to 5 pages and depending on which page the user is on the image at the top of the page needs to change.

So page 1 of the Post displays the image in custom field image_1, then page 2 displays the image in custom field 2 and so on...

I've set up my custom fields for the post but can't find reference to the function for detecting what page the user is on so I can add the function in to my template, what is the function I should be using?

  • can you share the codes where you have spilt the single post into five? – Maruti Mohanty Oct 3 '13 at 14:24
  • It's just using the standard <!--nextpage--> code – Vince Pettit Oct 3 '13 at 14:25

Current post page can be detected using get_query_var('page');.

note that if you do not pass any page the page 1 is shown, but get_query_var('page'); will be 0;

So in your function.php you can add:

function get_page_image() {
  global $post;
  if ( ! is_object($post) || ! isset($post->ID) ) return;
  $page = get_query_var('page');
  if ( empty($page) ) $page = 1;
  $field = 'image_' . $page;
  return get_post_meta($post->ID, $field, true);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.