SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    wordpress loop in single.php

    i found this code
    PHP Code:
    <?php if ( have_posts() ): while ( have_posts() ): the_post(); ?>
    using in the default theme
    single.php
    ? it's a redundant!because in the single.php,it's only one post, it's useless to use the while loop.am i right? why not delete it?

  2. #2
    SitePoint Evangelist runeveryday's Avatar
    Join Date
    Jul 2009
    Posts
    437
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    anyone helps?

  3. #3
    SitePoint Addict beebs93's Avatar
    Join Date
    Jul 2010
    Location
    Vancouver, Canada
    Posts
    207
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you check wp-includes/query.php, WP is basically checking that a post exists before attempting to render. While only one post should be "loaded" while viewing an individual post, the way WP checks this is the same if there are 100 posts or just one.

    If this wasn't checked for single.php (or loop-single.php) then a user who reloads a post that has just been removed (or visits a broken link) would most likely see an unfriendly PHP error -- probably about calling a method on a non-object (just a guess).
    "To be truly dedicated to something
    you must be willing to betray it.
    " -SW


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •