I have created my own theme and include the code for the main div of the home page below. What I want to do is to include just the latest post and have the pagination for earlier posts. I guess I’m missing something rather obvious as the pagination code. I realise the pagination code is redundant as it’s outside the while loop. Thanks!
<div id="main">
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<div <?php post_class(); ?>>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p class="published">Posted on
<?php the_time('j F Y'); ?>
by <?php the_author(); ?></p>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<div class="pagination">
<?php next_posts_link('Older'); ?>
<?php previous_posts_link('Newer'); ?>
</div>
<?php else : ?>
<h2>Nothing found</h2>
<p>Sorry, but there is nothing here to see.</p>
<?php endif; ?>
</div>
I’m also having trouble inserting code in this new forum!
Have you tried using WP_query() to just request the most recent post for display? There is a list of many different parameters that you can use with it to customize which posts you want to pull from the database here: http://codex.wordpress.org/Class_Reference/WP_Query as well as examples. If you are still stuck after you check out this resource, let us know.
http://www.researcheducatedevelop.com/blog/ - seems okay now. Must have been a temporary glitch. I changed your $my_query to $the_query since that is what I use elsewhere. I assume that was the right thing to do.
I realise I probably didn’t phrase my last post very well. The link to the blog is working again now but I still have a problem with the pagination. I have changed it so there are 2 posts to a page. As it happens there are currently only 4 posts on the blog. I get the “older posts” link as well as the newest 2 posts on the first page but here’s the rub: if I click on the older posts link I actually get the 2 older posts BUT looking at the page title it says Page not found.
Geez - I didn’t realise the title needed to be so complicated! Thanks. I’ll see what that does for me. The title seemed fine till I tried the pagination. Thanks WebMachine
It doesn’t have to be so complicated. I just like to use this one in all the themes I code, because it covers all the bases so I don’t have to customize every single one.
I think your title works fine on the first page because it is the home page of your blog, but when you go to the older posts, it doesn’t know which post title to use for wp_title, so it resorts to “page not found”. wp_title() usually picks up the title of a post if it is a single post on the page.
I would be very happy if someone could correct me if I’m wrong, or explain to you more clearly.