WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For instance, I am at http://url.com/single-post and in the post there is a link to the category that navigates to http://url.com/category/page/3/ which is the corresponding archive page that contains the current post.

I'm trying to pass a global variable from archive.php to single.php but it is not working:

echo '$page: '.$page.'<br />';
global $postCatPagenum;
$postCatPagenum = $page;
echo '$postCatPagenum: '.$postCatPagenum;

global $postCatPagenum;
echo '$postCatPagenum: '.$postCatPagenum;

Eventually I would like to make a function like this to run in single.php:

// Persistent category page
function persistant_cat_page() {
  global $postCatPagenum;
  $category = get_the_category(); 
  if (!$postCatPagenum){
      $pageUrl = '';
  } else {
      $pageUrl = '/page/'.$postCatPagenum;
      echo '<a href="'.get_category_link($category[0]->term_id).$pageUrl.'">'.$category[0]->cat_name.'</a>';


share|improve this question
Your post is going to be in a different page of your archives at different times. That makes it tricky. It could even change from one page to another between the time the link is created and the time it is clicked. What are you trying to accomplish? – s_ha_dum Feb 7 '13 at 0:51
I am trying to make it so when the user clicks the category that the post is in, that they see the post in context in the category. As an example Flickr does that with their photostream. This would actually work better with reverse pagination, because new posts would not change the pagination order: wordpress.stackexchange.com/questions/84851/… – user27068 Feb 7 '13 at 1:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.