Support » Themes and Templates » Single post!

  • Complex logic of WP continues to elude me.

    I need to display one single post (title and content) on a page. File “single.php” is supposedly dedicated for this. So, when user goes to page “”, he should see the post with id of 85. And that’s all! Only ONE post.

    If I’m insterting “the loop” in this page, ALL posts are listed.

    If I’m not inserting “the loop”, I cannot access “the_title()”, “the_content()”, and other post data.

    How I am to display single post in single.php ? ALL examples of single.php on the Internet for some unknown reason include “the loop”, and all of them display ALL posts! Why ??

    How I am to get current post and it’s data (title, content) that should be displayed according to the current URI “/p=85” ???

Viewing 10 replies - 1 through 10 (of 10 total)
  • Which theme are you using? Please post a link to your site.

    Just use


    You don’t need to loop as you are already on single.php.

    I’m building my own theme.

    the link should be:


    a wrong link might just get to use the index.php template if your theme does not have a 404 template (?)

    does your theme have a single.php?

    OK, I suppose I shoud’ve gotten into details from the start.

    I’m making my own Theme. I need a page, that would display only one Post.
    I found that file called “single.php” is used for it.

    So I’ve made it, here it is:

    <?php get_header(); ?>
    <?php get_sidebar(); ?>
      <?php the_post(); ?>
      <p><?php the_date(); ?>
      <p><?php the_category(', ') ?>
      <div class="thumb"><?php the_post_thumbnail(); ?></div>
      <p><?php the_content(); ?>
      <?php previous_post_link(); ?>
      <?php next_post_link(); ?>
      <?php the_tags(); ?>
    <?php get_footer(); ?>

    Site url is

    I’ve made two test posts.

    Post links are:

    But with this “single.php” file I always get only the post with id 85 (the latest of them), regardless of the address – either or displaying only one (latest) post.

    Interestingly enough, I discovered it just now – page title in the <title> html tag displayed properly, depending on the post id in the URI.
    It’s done by <?php wp_title(); ?> function in the “header.php”.

    But everything else is the same on this two pages, while it’s two different posts.

    is there anything in header.php or sidebar.php that could possibly mess with the original query?

    Sidebar is (excluding texts):

    <!-- Sidebar -->
      <td id="sidebar" valign="top">
          global $post;
          switch ( get_post( $post )->post_name ) {
              echo "<ul id='contents'>\n";
              echo "</ul>\n";
          query_posts($query_string . '&post_type=post');
          while ( have_posts() ) : the_post();
            echo ' <a href="'.get_permalink().'">';
            echo '</a><br>';
      <td class="content" valign="top">
        <div class="content">
    <!-- /Sidebar -->





    Well, it almost helped, thanks!

    One small problem left: date of first post doesn’t show.
    The one that should be where <?php the_date(); ?> is.

    I found out that this could happen in a loop and when dates are the same. However, it’s not a loop and dates are different.

    But with the_time(‘d.m.Y’) date is displayed correctly. Strange.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Single post!’ is closed to new replies.