WordPress.org

Ready to get started?Download WordPress

Forums

post pagination inside template page set to show specific category (9 posts)

  1. connectto
    Member
    Posted 2 years ago #

    hello I'm having trouble creating a navigation in the posts that are being directed to a page template.

    simply does not appear any button to "older posts" as you can see here http://travelcouture.com.br/?page_id=589

    I tried to add to my template page the following code - in a wordpress copy that i have installed on my test server:

    <?php query_posts('cat=40&showposts=6'.'&paged='.$paged);?>

    and at the end of the page

    <?php endwhile; // end of the loop. ?>
    <div class="navigation">
    <span class="nav-previous"><?php echo previous_post_link(); ?></span>
    <span class="nav-next"><?php echo next_post_link(); ?></span>

    [Please post code or markup snippets between backticks or use the code button.]

    with this code i could bring up the buttons but they link to isolated single post pages and not to a "second page" with a list of several posts.

    I read somewhere about instead of using a page template I should use a template category file (do not know how to use it actually) but do not know how to call a template class inside a pages menu - i need a link to this category in my main pages menu.

    actually it is already running in the middle of the pages menu - I have the link "Travel tips" which sends to a template page that shows the "Travel" category
    - the problem is that this template page with travel category posts dont have pagination - i cant navigate to older posts ..

    Anyone know how to make the pagination work properly in my template page

    or

    if the best option is to actually create a "template class" and call it in some way on the menu

    - How can I solve this problem?

    (sorry my english is not so good )

  2. connectto
    Member
    Posted 2 years ago #

    the full code of my template page :

    [Code moderated as per the Forum Rules. Please use the pastebin]

  3. alchymyth
    Forum Moderator
    Posted 2 years ago #

    in multi-post-pages such a category archives, try to work with

    next_posts_link() and previous_posts_link()

    http://codex.wordpress.org/Function_Reference/next_posts_link

    http://codex.wordpress.org/Function_Reference/previous_posts_link

    also, you might need to use:

    <?php query_posts('cat=40&showposts=6'.'&paged='.get_query_var('paged'));?>
  4. connectto
    Member
    Posted 2 years ago #

    thanx alchymyth its partialy solved with your tips.

    now the "older posts" buttons appear, and i can navigate to the other pages page_id=589&paged=2 , page_id=589&paged=3 , etc

    but the content is allways the same, the posts of paged=1

    50% solved anyone can help to solve the other 50% hehe ?

  5. alchymyth
    Forum Moderator
    Posted 2 years ago #

    have you seen and tried the second part of my previous reply - to change the query to:

    <?php query_posts('cat=40&showposts=6'.'&paged='.get_query_var('paged'));?>

  6. connectto
    Member
    Posted 2 years ago #

    hello alchymyth thanx for your reply !

    about your question: yes i changed that part also

    now the navigation button appears but all pages show the first page content ..

    heres the link http://www.travelcouture.com.br/?page_id=9

    well i could solve all the problems till now - this is the only one i couldnt solve anyway :( - hope you or someone can give me a hand heheh

    really thanx alchymyth for your support !

    heres my complete code now (with the changes that alchymyth posted):

    <?php
    /*
    Template Name: Viagem
    */
    ?>
    <?php
    /**
    * The template for displaying all pages.
    *
    * @package WordPress
    * @subpackage Matala
    */

    get_header(); ?>

    <div id="primary">
    <div id="content" role="main">
    <?php query_posts('');?>
    <?php query_posts('cat=40&showposts=6'.'&paged='.get_query_var('paged'));?>
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    <header class="page-header">
    <h1 class="page-title"><?php the_title(); ?></h1>
    </header><!-- .page-header -->

    <div class="entry-content">
    <?php the_content(); ?>
    <?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'matala' ) . '</span>', 'after' => '</div>' ) ); ?>
    </div><!-- .entry-content -->
    <div class="entry-meta">
    <?php edit_post_link( __( 'Edit', 'matala' ), '<span class="edit-link">', '</span>' ); ?>
    </div><!-- .entry-meta -->
    </article><!-- #post-<?php the_ID(); ?> -->

    <?php comments_template( '', true ); ?>

    <?php endwhile; // end of the loop. ?>
    <div class="navigation">
    <span class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older <span>posts</span>', 'matala' ) ); ?></span>
    <span class="nav-next"><?php previous_posts_link( __( 'Newer <span>posts</span> <span class="meta-nav">→</span>', 'matala' ) ); ?></span>
    </div>

    </div><!-- #content -->

    <?php
    /* Two columns of sidebars.
    */
    get_sidebar( 'supplementary' );
    ?>
    <div id="primary-bottom"></div>
    </div><!-- #primary -->

    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

  7. connectto
    Member
    Posted 2 years ago #

    tried other solutions looking in google - till now nothing worked

    the only advance i had was with alchymyth tip - initially the older posts button didnt even appear

    then i did the changes and now i can see olde posts button - when i click in it i see i navigate to page 2, page 3 etc - but all pages show same content

    found some material here in forum and google - most of the posts talk about this but not in a template page situation

    anyway i tried the solutions i found in my research and nothing worked

    im really with a big problem - need to solve it with some urgency .. anyone have a clue about whats going on ?

    (sorry my bad english)

  8. connectto
    Member
    Posted 2 years ago #

    ok solved with the code below:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    <?php query_posts("cat=41,8&showposts=6&paged=$paged"); ?>
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

    really thanx alchymyth !

  9. josh-ruther4d
    Member
    Posted 1 year ago #

    Connectto, I'm having a very similar problem! I have a static page (that is not a front page) displaying my portfolio. I am having success pulling the images and posts that I need, however I'm having pagination issues. Pagination links will show up, but when I click on them it just shows the same content again. Here's the code that I have...I've tried a bunch of different solutions, but nothing seems to change it. Thanks in advance to anyone that can help! You can see the problem at http://josh-ruther4d.com/portfolio.php

    This is at the top of the page to initialize wordpress

    <?php
      // Include WordPress
      define('WP_USE_THEMES', false);
      global $wpdb;
      require_once('./wp-config.php');
      query_posts('showposts=99');
    ?>

    And then I have this

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
    <?php query_posts("showposts=1&paged=$paged"); ?>
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    
     //do stuff
    
    <?php endwhile; ?>
    
    <?php posts_nav_link(); ?>

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum's parser.]

Topic Closed

This topic has been closed to new replies.

About this Topic