Single post! (11 posts)

  1. sly_g
    Posted 2 years ago #

    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 "site.com/p=85", 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" ???

  2. kjodle
    Posted 2 years ago #

    Which theme are you using? Please post a link to your site.

  3. kpry44
    Posted 2 years ago #

    Just use


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

  4. sly_g
    Posted 2 years ago #

    I'm building my own theme.

  5. Michael
    Part-Time Forum Moderator
    Posted 2 years ago #

    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?

  6. sly_g
    Posted 2 years ago #

    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 http://golovanov.net/biosea/

    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 http://golovanov.net/biosea/?p=85 or http://golovanov.net/biosea/?p=1 displaying only one (latest) post.

  7. sly_g
    Posted 2 years ago #

    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.

  8. Michael
    Part-Time Forum Moderator
    Posted 2 years ago #

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

  9. sly_g
    Posted 2 years ago #

    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 -->
  10. Michael
    Part-Time Forum Moderator
    Posted 2 years ago #





  11. sly_g
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic