WordPress.org

Ready to get started?Download WordPress

Forums

'Older Entries' Not Working (11 posts)

  1. forgewithinfire
    Member
    Posted 4 years ago #

    I have had a blog going well for a while now but when I finally had enough posts that an 'older entries' link appeared at the bottom, it simply shows you the same content as the static home page (where the blog is).

    I found a few posts that dealth with similar problems, but I have almost no PHP knowledge and none of those fixes worked for me. Here is what I have:

    <div id="content" class="narrowcolumn" role="main">
    			<?php if (have_posts()) : ?>
    
    			<?php /*$my_query = new WP_Query('category_name=events&showposts=3');
    			while ($my_query->have_posts()) : $my_query->the_post();
    			$do_not_duplicate = $post->ID; */ ?>
    
    			<?php query_posts('cat=5'); while (have_posts()) : the_post(); ?>
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    				<div class='news_item'>
    				<p class='news_headline'><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    				<!-- <small><?php the_time('F jS, Y') ?>   ?> </small> Date & Time Code-->
    
    				<div class="entry">
    					<?php the_content('Read the rest of this entry &raquo;'); ?>
    				</div><hr><br />
    
    			</div>
    
    			<?php endwhile; ?>
    
    			<div class="navigation">
    				<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    				<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    			</div>
    
    			<hr />
    
    			<?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(); ?>
    			<?php endif; ?>
    		</div>
    	</div>
    	<?php wp_reset_query(); ?>
  2. Jonas Grumby
    Member
    Posted 4 years ago #

    Well, somebody wrote that code for you because it is not standard.

    At a glance it seems to be saying to show 3 posts from the events category and then the posts from category 5, whatever that is.

    You probably need all of that to be Conditional so that it only applies on the main page.

    Just glancing at it and taking a best guess.

  3. forgewithinfire
    Member
    Posted 4 years ago #

    I originally cut the loop from the default theme and had a third party make it display only posts from a specific category... but friends of friends of friends can make mistakes.

    I wouldn't mind starting over, I just need to know the loop code for displaying posts from a specific category that also allows for proper pagination to avoid the previous problem with older posts.

  4. Jonas Grumby
    Member
    Posted 4 years ago #

    If you replace this code

    <?php /*$my_query = new WP_Query('category_name=events&showposts=3');
    while ($my_query->have_posts()) : $my_query->the_post();
    $do_not_duplicate = $post->ID; */ ?>
    <?php query_posts('cat=5'); while (have_posts()) : the_post(); ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <div class='news_item'>
    <p class='news_headline'><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>

    with standard loop code (e.g. from the Default theme)

    <?php while (have_posts()) : the_post(); ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>

    your site should behave normally again. Remember to make backups in case what you do doesn't work and you have to put it back to the way it was.

  5. forgewithinfire
    Member
    Posted 4 years ago #

    But does this tell the loop to only display posts from a specific category?

  6. forgewithinfire
    Member
    Posted 4 years ago #

    I found a post stating that the query_posts could be problematic due to the fact it overrides other parameters, hence the pagination issue.

  7. Jonas Grumby
    Member
    Posted 4 years ago #

    1) No it does not

    2) Yes it does

    If you only want to display posts from one category on the home page, there are certainly other ways to do that. For example, you could use a Page Template.

  8. forgewithinfire
    Member
    Posted 4 years ago #

    Please take a look at the page I'm working on:

    http://www.clevelandnorml.org

    This isn't a traditional blog, let me explain:

    There are 4 individual loops on the home page (a static page btw), each one to display posts from a single category. Meetings, meetings_sidebar, events and featured content. The loop displaying posts from the 'featured content' category is the only one that will EVER have an 'older entries' link, or ever need one.

    I set this up with wordpress as a content management system that even the well intentioned flakes I work with can use (visit the site, you will know why they are flakes). I know HTML/XHTML/CSS etc, my co-workers do not. The problem is I don't know PHP.

    I used this code I found on another forum topic, but it didn't work:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("cat=5&paged=$paged"); ?>
  9. forgewithinfire
    Member
    Posted 4 years ago #

    Sorry, the site probably didn't work for you, it will now.

  10. alchymyth
    Forum Moderator
    Posted 4 years ago #

    if i had to work with a site with four loops and pagination, i would try to be clear about:
    1. which of the loops is supposed to paginate? (for you that would be the 'featured')
    2. a. do i want to show the other 'loops' on the paginated pages in the same way as they are on the front page?
    2. b. - or not at all?
    2. c. - or only some of them?

    > i would save the original query data in a variable at the beginning of the page;
    (or use the technique described in http://codex.wordpress.org/The_Loop#Multiple_Loops_Example_1 to keep the original query;)
    > if 2a is to show different posts of these loops on pagination, that would need some interesting custom programming;
    > in case of 2b/2c use conditional tag 'is_paged()' to influence the other loops;
    > restore the original query for the paginated loop;
    > use the $paged code as in your example;
    > save the query back to the variable direct after this loop;
    > run the other loop(s) (for instance the one in your sidebar);
    > restore the original query at the end of the page;

    that should hopefully create a smooth working pagination.

  11. ceragraves
    Member
    Posted 3 years ago #

    Hi - I am having a similar problem and could really use some help.

    My blog: sarahnicklin.com/blog works fine except that when you click on the older posts button, it continues to show the same posts. The url changes to the second page, but the posts remain the same. I've been going through many of the posts here and have found people with the same problems and have tried using the solutions that people suggested, but it hasn't worked.

    Please help. Here is the code from the index page (Note that this is from the "notepad chaos" theme)

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
        <div class="post" id="post-<?php the_ID(); ?>">
          <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>
          <div class="post-inner">
            <div class="date-tab"><span class="month"><?php the_time('F') ?></span><span class="day"><?php the_time('j') ?></span></div>
            <div class="thumbnail"><?php $key="thumbnail"; echo get_post_meta($post->ID, $key, true); ?></div>
    		<?php the_content('Read the rest of this entry &raquo;'); ?>
          </div>
          <div class="meta"><?php the_tags('Tags: ', ', ', '<br />'); ?>posted under <?php the_category(', ') ?> |  <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></div>
        </div>
        <?php endwhile; ?>
        <div class="post-nav"><span class="previous"><?php next_posts_link('&laquo; Older Entries') ?></span><span class="next"><?php previous_posts_link('Newer Entries &raquo;') ?></span></div>
        <?php else : ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.