Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

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

//single.php
<?php
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;
  }
  if($category[0]){
      echo '<a href="'.get_category_link($category[0]->term_id).$pageUrl.'">'.$category[0]->cat_name.'</a>';
  }
}

Thanks!

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

 
discard

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

Browse other questions tagged or ask your own question.