WordPress.org

Ready to get started?Download WordPress

Forums

Previous Post link does not work (5 posts)

  1. truthlighthouse
    Member
    Posted 3 years ago #

    Hello,

    I am having trouble getting my previous post link to work at the bottom of my home page (TruthLighthouse.com). My theme originally did not have a previous post link so I started working on trying to get one. For now, it has a simple link that takes them to the archives but I literally want it to go to the list of the previous posts. I read various topics on the subject and none seemed to work. I tried editing the index.php with the following code - <?php next_posts_link('Older Entries »', 0); ?><?php previous_posts_link('« Newer Entries', 0) ?> and at first, it seems to be working. It produces a previous post link at the bottom. If I click it, however, it simply reproduces the same page. It does not list the older posts. Below is the code I currently have.

    <!-- Middle Column -->
    		<div id="midcolumn">
    			<h2>Recent Posts</h2>
    			<!-- Loop for latest news -->
    			<?php $oddentry = 'class="gray" '; ?>
    			<?php query_posts('cat=13,14,15,16,17,18,19,20,21,29,30,22,23,24,25,28,26,27&orderby=rand&showposts=10'); ?>
    			<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    			<div <?php echo $oddentry; ?>>
    				<div class="midcolumnpost">
    					<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    					<?php the_excerpt('Read More', '<img><a>', 'content', false, 'More...', true);?>
    					<div class="details">
    						 | <a href="<?php echo get_permalink(); ?>" title="Read More">Read More</a>
    					</div>
    				</div>
    			</div>
    			<?php /* Changes every other post to a different class */	$oddentry = ( empty( $oddentry ) ) ? 'class="gray" ' : ''; ?>
    			<!-- End of Loop for middle column -->
    			<?php endwhile; else : ?>
    			<?php endif; ?>
    <center><b><u><a href="http://www.truthlighthouse.com/archives/">>>>Older Posts<<<</a></u></b></center>
    		</div>
    		<!-- /Middle Column -->

    I tried the following code and got the results mentioned above.

    <!-- Middle Column -->
    		<div id="midcolumn">
    			<h2>Recent Posts</h2>
    			<!-- Loop for latest news -->
    			<?php $oddentry = 'class="gray" '; ?>
    			<?php query_posts('cat=13,14,15,16,17,18,19,20,21,29,30,22,23,24,25,28,26,27&orderby=rand&showposts=10'); ?>
    			<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    			<div <?php echo $oddentry; ?>>
    				<div class="midcolumnpost">
    					<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    					<?php the_excerpt('Read More', '<img><a>', 'content', false, 'More...', true);?>
    					<div class="details">
    						 | <a href="<?php echo get_permalink(); ?>" title="Read More">Read More</a>
    					</div>
    				</div>
    			</div>
    			<?php /* Changes every other post to a different class */	$oddentry = ( empty( $oddentry ) ) ? 'class="gray" ' : ''; ?>
    			<!-- End of Loop for middle column -->
    			<?php endwhile; else : ?>
    			<?php endif; ?>
    <center><b><u><?php next_posts_link('Older Entries »', 0); ?><?php previous_posts_link('« Newer Entries', 0) ?></u></b></center>
    		</div>
    		<!-- /Middle Column -->

    Any ideas why this will not show the actual previous posts?

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    you have this custom query in your code:
    <?php query_posts('cat=13,14,15,16,17,18,19,20,21,29,30,22,23,24,25,28,26,27&orderby=rand&showposts=10'); ?>
    without the 'paged' parameter:
    http://codex.wordpress.org/Function_Reference/query_posts#Pagination_Parameters

    search for 'query_posts() pagination' shold give you some solutions

  3. truthlighthouse
    Member
    Posted 3 years ago #

    I am very new to PHP but I did some research and I think I see what you mean. From what I gather, since I am calling only select categories using query posts, it is unable to paginate. So I tried to input various lines of codes but none of them produce the necessary results. I checked out that link that you mentioned and saw the line that you referred to about "paged" but whenever I inserted that, it did not resolve the issue. I think I need additional lines of code which is where I fall off the wagon since I know no code. I searched Google and found a website that offered up something where it created a variable which is probably what I need but I don't know exactly how to use it. Could you possibly clarify what you are referring to? Maybe an example of how the code should read would really help. Thanks so much for your assistance!

  4. truthlighthouse
    Member
    Posted 3 years ago #

    I found an amazingly similar situation in another topic but I tried this and it did not work. Maybe I set it up wrong?


    Similar topic

    I tried the code below using the method listed but it did not work:

    <!-- Middle Column -->
    		<div id="midcolumn">
    			<h2>Recent Posts</h2>
    			<!-- Loop for latest news -->
    			<?php $oddentry = 'class="gray" '; ?>
    			<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=13,14,15,16,17,18,19,20,21,29,30,22,23,24,25,28,26,27&orderby=rand&showposts=10&paged=$paged"); ?>
    			<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    			<div <?php echo $oddentry; ?>>
    				<div class="midcolumnpost">
    					<h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    					<?php the_excerpt('Read More', '<img><a>', 'content', false, 'More...', true);?>
    					<div class="details">
    						 | <a href="<?php echo get_permalink(); ?>" title="Read More">Read More</a>
    					</div>
    				</div>
    			</div>
    			<?php /* Changes every other post to a different class */	$oddentry = ( empty( $oddentry ) ) ? 'class="gray" ' : ''; ?>
    			<!-- End of Loop for middle column -->
    			<?php endwhile; else : ?>
    			<?php endif; ?>
    		</div>
    		<!-- /Middle Column -->
  5. truthlighthouse
    Member
    Posted 3 years ago #

    alchymyth - Would you be able to give me some further guidance on what you are suggesting? I am very new so some of this does not make sense to me. I reviewed the links and continued researching but was unable to determine exactly what code I might need to make it happen.

    Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic