• Resolved downfast

    (@downfast)


    Hi,
    i am trying to add a previous and next post link on my page, i have tried many options by reading the wp codex but i don’t seem to make it work.

    Any help please?

    This is my page

    <?php
    /*
    Template Name: Blog
    */
    get_header(); ?>
    
    <div id="content" class="narrowcolumn" role="main">
    
    <?php query_posts("cat=1"); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <div id="blog" class="clearfix" >
    
    			<div <?php post_class("blogpost clearfix") ?> id="post-<?php the_ID(); ?>">
    			<div class="postImg">
    		<?php get_the_image( array( 'custom_key' => array( 'medium', 'medium' ), 'default_size' => 'medium' ) ); ?>
    		</div>
    		<div class="postContent">
    				<h2 class="blogHeading"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    				<p class="date"><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></p>
    
    				<div class="entry">
    					<?php the_content('Read the rest of this entry &raquo;'); ?>
    				</div>
    
    				</div>
    <p><?php previous_post('%', 'Previous:', 'no'); ?>
    | <?php next_post('%', 'Next:', 'no'); ?></p>
    		<?php endwhile; ?>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    	</div>
    	<?php endif; ?>
    </div>
    
    <?php get_footer(); ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • <div class="postnav">
    
    			<div class="alignleft"><?php previous_post_link('&laquo; %link') ?></div>
    			<div class="alignright"><?php next_post_link('%link &raquo;') ?></div>
    </div>

    dunno if this helps…here’s mine (I put it in the same place you have yours in the code)

    Thread Starter downfast

    (@downfast)

    hi thanks, nothing shows up, i don’t understand…

    Thread Starter downfast

    (@downfast)

    for example this code shows me previous and next page but if i click doesn’t work, see the bottom of the code

    <?php
    /*
    Template Name: Blog
    */
    get_header(); ?>
    
    <div id="content" class="narrowcolumn" role="main">
    
    <?php query_posts("cat=1"); ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <div id="blog" class="clearfix" >
    
    			<div <?php post_class("blogpost clearfix") ?> id="post-<?php the_ID(); ?>">
    			<div class="postImg">
    		<?php get_the_image( array( 'custom_key' => array( 'medium', 'medium' ), 'default_size' => 'medium' ) ); ?>
    		</div>
    		<div class="postContent">
    				<h2 class="blogHeading"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    				<p class="date"><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></p>
    
    				<div class="entry">
    					<?php the_content('Read the rest of this entry &raquo;'); ?>
    				</div>
    
    				</div>
    
    		<?php endwhile; ?>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    	</div>
    	<?php endif; ?>
    </div>
    <div class="navigation"><p><?php posts_nav_link(); ?></p></div>
    </div>
    
    <?php get_footer(); ?>

    Thread Starter downfast

    (@downfast)

    anyone?

    $max_entries_per_page = 10;
    $current_page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    query_posts("cat=1&paged=" . $current_page)
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <!-- BLA BLA BLA BLA -->
    <?php endwhile; ?>
    <?php endif; ?>
    
    <?php next_posts_link('? Older Entries', $max_entries_per_page) ?>
    <?php previous_posts_link('Newer Entries ?', $max_entries_per_page) ?>
    Thread Starter downfast

    (@downfast)

    it works, thanks.

    final code:

    <?php
    /*
    Template Name: Blog
    */
    get_header(); ?>
    
    <div id="content" class="narrowcolumn" role="main">
    
    <?php $max_entries_per_page = 10;
    $current_page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    
    query_posts("cat=1&paged=" . $current_page)?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    
    <div id="blog" class="clearfix" >
    
    			<div <?php post_class("blogpost clearfix") ?> id="post-<?php the_ID(); ?>">
    			<div class="postImg">
    		<?php get_the_image( array( 'custom_key' => array( 'medium', 'medium' ), 'default_size' => 'medium' ) ); ?>
    		</div>
    		<div class="postContent">
    				<h2 class="blogHeading"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    				<p class="date"><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></p>
    
    				<div class="entry">
    					<?php the_content('Read the rest of this entry &raquo;'); ?>
    				</div>
    
    				</div>
    <?php previous_post_link('&laquo; %link') ?>
    		<?php endwhile; ?>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    	</div>
    	<?php endif; ?>
    </div>
    <?php next_posts_link('? Older Entries', $max_entries_per_page) ?>
    <?php previous_posts_link('Newer Entries ?', $max_entries_per_page) ?>
    
    <?php get_footer(); ?>

    you’re welcome ^_^

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘previous and next post not working’ is closed to new replies.