Support » Themes and Templates » "Older Entries" & "Newer Entries" doesn't appear. Code ignored?
"Older Entries" & "Newer Entries" doesn't appear. Code ignored?
-
Hi!
I use this code to get the classic navigation menue at the end of the page:<?php endwhile; ?> <div class="text_datum"> <?php next_posts_link('« Older Entries') ?> <?php previous_posts_link('Newer Entries »') ?> </div> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
But the navigation doesn’t appear. This is the output: http://www.conceptualisms.org/main/
Acutally I’d like to have a navigation that only shows the “Newer Entries” if there are actually newer entries of the same category. But I thought it might be a good idea to start with this simple code to see, if it works in general. It does not, and it’s really frustrating me. I would be thankful for any help.Kind Regards
Pat
-
What template file are you adding this to?
Hi esmi, maybe I don’t understand your question. The outputsite is http://www.conceptualisms.org/main/
And the whole code of this page is<?php get_header(); ?> <div id="inhalt" class="text_single"> <?php $custom_query = new WP_Query('category_name=books,texts,news'); // exclude category 9 bzw. reblog while($custom_query->have_posts()) : $custom_query->the_post(); ?> <div <?php post_class(); ?> id="post-<?php the_ID(); ?>"> <h1 class="text_autor"><a href="<?php the_permalink(); ?>"><?php echo get_post_meta($post->ID, 'Autor', true); ?>, <?php the_title() ?></a></h1></p> <p class="text_datum"><?php the_date();?></p> <?the_excerpt(); ?> </div> <p>−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−</p> <?php endwhile; ?> <div class="text_datum"> <?php next_posts_link('« Older Entries') ?> <?php previous_posts_link('Newer Entries »') ?> </div> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
Is that what you asked for?
Why are you using WP_Query()? Is this a custom page template?
Yes it is a costum page template, but it was not my decision. Unfortunately, the former programmer can’t work on it anymore. If there’s a better solution than WP_Query() that makes it easier to get the navigation, I’m open to it.
WP_Query() should only be used for secondary queries – not the main query. Try using pre_get_posts() instead.
using next-posts-link with custom query:
Thank you. I tried it out. I use the code, I just found here https://codex.wordpress.org/Pagination
and changed it a bit, so it should appear in my area “inhalt”, which means “content”:<?php get_header(); ?> <div id="inhalt" class="text_single"> <?php if ( have_posts() ) : ?> <!-- Add the pagination functions here. --> <!-- Start of the main loop. --> <?php while ( have_posts() ) : the_post(); ?> <!-- the rest of your theme's main loop --> <?php endwhile; ?> <!-- End of the main loop --> <!-- Add the pagination functions here. --> <div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div> <div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div> <?php else : ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
Now nothing appears at all. What did I do wrong?
Ok, I see that the code is just a basic structure.
So I found this https://codex.wordpress.org/the_loop and tried it out:<?php get_header(); ?> <div id="inhalt" class="text_single"> <?php query_posts($query_string . '&cat=-40'); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="post"> <!-- Display the Title as a link to the Post's permalink. --> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <!-- Display the date (November 16th, 2009 format) and a link to other posts by this posts author. --> <small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small> <div class="entry"> <?php the_content(); ?> </div> <p class="postmetadata">Posted in <?php the_category(', '); ?></p> </div> <!-- closes the first div box --> <?php endwhile; else: ?> <p>Sorry, no posts matched your criteria.</p> <?php endif; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>
But the only thing I get is one single post, but I already have 8. Why is the loop not working? Any suggestions? It looks so simple.
Is there no working simple loop with pagination out there for an archive of posts?
&cat=-40')
is just to make this to have no effect, as there is no cat with the id 40.
- The topic ‘"Older Entries" & "Newer Entries" doesn't appear. Code ignored?’ is closed to new replies.