• Resolved NormalWebEditor

    (@normalwebeditor)


    Here’s the page I’m working on: http://thenormalschool.com/sunrise/?page_id=166

    I have my posts listed by category, and when you click on “more nonfiction” at the bottom, it displays only posts of that category. So that’s all great. The only problem is that when you click more, the heading changes from “Nonfiction” to “What’s Normal Now.” What’s Normal Now is the heading of the index.php file. How do I get it to continue using the same page template when using the next_post_link ?

    Thanks in advance for any insight you can offer.

Viewing 8 replies - 1 through 8 (of 8 total)
  • By default, the next_post_link() parameter in_same_term is set to ‘false’. Try editing the template and set this parameter to ‘true’.

    You should create a Child theme to make your changes. If you do not, all of your changes will be lost if you update your theme.

    Thread Starter NormalWebEditor

    (@normalwebeditor)

    I’m not using a template. I’m assuming I would need to create a functions.php file and add… what to it?

    What theme are you using? If it is a free theme, someone can look at the code and give more specific advice. If it is a paid theme, you should contact the theme author.

    Thread Starter NormalWebEditor

    (@normalwebeditor)

    I’m not using a theme. I’m using wordpress as a CMS for a website I designed myself.

    If you did not follow the standard WP template hierarchy, I have no way of knowing what you need to do.

    Thread Starter NormalWebEditor

    (@normalwebeditor)

    Hmm… Well here’s my code:

    <h1>Nonfiction</h1>
    <?php query_posts('category_name=nonfiction&showposts=4');
    while (have_posts()) : the_post();
      // do whatever you want
    ?>
    <div id="post">
    
    <div id="thumb">
    <?php
      preg_match_all("/(<img [^>]*>)/",get_the_content(),$matches,PREG_PATTERN_ORDER);
      for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) {
        echo $beforeEachImage . $matches[1][$i] . $afterEachImage;}?>
    </div>
    <div id="pcontent">
    <h2><?php the_title(); ?></h2>
    <p><em><?php the_time('F jS, Y') ?></em></p>
    <p><?php
      ob_start();
      the_content('Read the full post',true);
      $postOutput = preg_replace('/<img[^>]+./','', ob_get_contents());
      ob_end_clean();
      echo $postOutput;
      ?></p>
    </div>
    </div>
    <?php endwhile; ?>
    
    <div id="more">
    <p><?php next_post_link('%link', 'More Nonfiction', TRUE, $in_same_term = TRUE); ?></p>

    I’ll admit that I’ve never looked at the standard template hierarchy, but–now that I have–I can’t seem to make heads or tails of my problem. To reiterate, I just want the page to display the older posts on the same page template that the original nonfiction posts appear. Why, when I click on “More Nonfiction” does it revert to the index.php template? How do I stop that from happening? I have tried making category-nonfiction.php and also category-4.php (the cat id) and also page-179.php (it seems to display the extra posts at ?p=179). What am I doing wrong?

    To make pagination work, you must get the current page number and include it in your query_posts(), something like this (untested):

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') :
       ((get_query_var('page')) ? get_query_var('page') : 1 );
    query_posts('category_name=nonfiction&showposts=4&paged=' . $paged);

    Then, instead of using next_post_link(), which is intended to get the next single post, use next_posts_link() and previous_posts_link() for navigation.

    Thread Starter NormalWebEditor

    (@normalwebeditor)

    It works! Thanks so much!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘next_post_link and category pages’ is closed to new replies.