WordPress.org

Ready to get started?Download WordPress

Forums

Display posts on page in custom theme (8 posts)

  1. thiazzi
    Member
    Posted 2 years ago #

    I created a custom theme by turning regular HTML pages into page templates, pretty much. I thought this site was just going to be completely static, but then I was asked to implement a blog page.

    For the life of me, I can't figure out how to get POSTS into one of these page templates. I copied the following code out of the codex, but all it does is diplay the PAGE title and edit button, rather than displaying a post:

    <?php if (have_posts()) : while (have_posts()) : the_post();?>
      <h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
      <div class="entrytext">
       <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
      </div>
     <?php endwhile; endif; ?>
     <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>

    I need to get at least the most recent post onto this page, and ideally the last three. I've scoured the site and can't find anybody in my particular situation. Any ideas?

  2. alchymyth
    Forum Moderator
    Posted 2 years ago #

    you need to add a custom query before the loop:
    http://codex.wordpress.org/Function_Reference/query_posts

    example:
    <?php query_posts('posts_per_page=3&post_type=post'); ?>

    or if this is the secondary loop:
    http://codex.wordpress.org/Class_Reference/WP_Query

    http://codex.wordpress.org/The_Loop

    it might help if you paste the full page template code into a http://pastebin.com/ and post the link to it here (how-to) so someone can check it.

  3. esmi
    Forum Moderator
    Posted 2 years ago #

  4. thiazzi
    Member
    Posted 2 years ago #

    Thanks for some quick replies: More information that I probably should have included: This is not a child of another theme (again--this was supposed to be all static!), so it's very possible I'm missing some function stuff that I need. Is there a simple way to pull that over from another theme?

  5. esmi
    Forum Moderator
    Posted 2 years ago #

    This is not a child of another theme

    That doesn't matter.

    Is there a simple way to pull that over from another theme?

    No - you need to create a new custom page template for your theme.

  6. thiazzi
    Member
    Posted 2 years ago #

    Here is the code that I'm using to try and pull in posts: http://pastebin.com/dnFActqt

    It is outputting this on my page:

    Post navigation
    ← Previous
    blog

    Reply

    content

    Leave a reply Edit
    Leave a Reply
    Logged in as admin. Log out?

    Comment

    You may use these HTML tags and attributes: etc. etc.

    "blog" and "content" are the Name and Content of this page, respectively. This means that it is pulling information from my PAGES instead of my POSTS. Is there a way to fix this?

  7. esmi
    Forum Moderator
    Posted 2 years ago #

    See the link I posted above.

  8. thiazzi
    Member
    Posted 2 years ago #

    Thanks, esmi. I have posts on my page now by using the example code on page-of-posts and referring to the twentyeleven theme instead of my own woeful custom theme.

Topic Closed

This topic has been closed to new replies.

About this Topic