WordPress.org

Ready to get started?Download WordPress

Forums

Single.php Broken (4 posts)

  1. brianfeister
    Member
    Posted 5 years ago #

    So I've copied a previously designed custom theme and am skinning it for a new project. When I click a post permalink, I get "Sorry, no posts matched your criteria".

    I thought that possibly this was because permalinks were bad so I updated them just to be sure.

    I've also updated my .htaccess file just to be sure the correct WordPress mods were in there.

    So what it seems is that somewhere in my code, there is a broken element, because when I switch to the default theme everything is fine. The strange thing is that when I copy and paste the contents of the default "single.php" I still have the same error (and layout bugs show that I'm looking at a the fresh non-cached single.php)... Not sure why it still won't display the loop when I copy the default single.php, that's baffling.

    My code is below... any help?

    <?php get_header(); ?>
    
       <!-- MAIN PRIMARY: MAIN FOCUS AREA, MISSION STATEMENT, WHO WE ARE, ETC -->
       <div id="main_primary">
           <div class="content">
           <?php if (have_posts()) : while (have_posts()) : the_post();
    		// check for thumbnail
    		$thumb = get_post_meta($post->ID, 'thumbnail', $single = true);
    		// check for thumbnail class
    		$thumb_class = get_post_meta($post->ID, 'thumbnail class', $single = true);
    		// check for thumbnail alt text
    		$thumb_alt = get_post_meta($post->ID, 'thumbnail alt', $single = true);
    
    	   ?>
    
                   <div class="post" id="post-<?php the_ID(); ?>">
    				<div class="titlemeta">
                   <h2 class="post_title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                   <span class="date icon_swap">
                           <span class="month"><?php the_time('F jS, Y') ?></span>
                   </span>
                   <span class="comments_link icon_swap">
                           <a href="#main_secondary">
                           <?php comments_number('Add a Comment', '1 Comment', '% Comments'); ?>
                           </a>
                   </span>
                   <?php the_tags('<br /><span class="tags icon_swap">', ', ', '</span>'); ?>
    
                    <br class="clear" />
              </div>
                           <div class="entry">
    							<?php // if there's a thumbnail
                                if($thumb !== '') { ?>
                                    <div>
                                    <img src="<?php echo $thumb; ?>"
                                    class="<?php if($thumb_class !== '') { echo $thumb_class; } else { echo "post_thumb"; } ?>"
                                    alt="<?php if($thumb_alt !== '') { echo $thumb_alt; } else { echo the_title(); } ?>"
                                    />
                                    </div>
                                <?php } // end if statement
    
                                // if there's not a thumbnail
                                else { echo ''; } ?>
    
                                   <?php the_content(); ?>
    
                                   <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    
    								<div class="social_bookmarks">
    
                                   <h4 class="social_bookmarks_title">Was it good?  If so, tell the world:</h4>
    
                                   <ul class="icons">
                                           <li class="twitter_s">
                                           			<?php tweet_this($service, $tweet_text, $link_text, $title_text, $icon_file, $a_class, $img_class, $img_alt) ?>
                                                    <span>Twitter.com - Tweet This!</span>
    
                                           </li>
                                           <li class="facebook_s">
                                                   <a href="http://www.facebook.com/share.php?u=<?php the_permalink(); ?>&h=<?php the_title(); ?>">
                                                           Facebook
                                                   </a>
                                                   <span>Facebook.com - Post on Facebook</span>
                                           </li>
                                           <li class="stumble_upon_s">
                                                   <a href="http://www.stumbleupon.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>">
                                                           Stumble Upon
                                                   </a>
                                                   <span>Stumble Upon.com - Stumble This!</span>
                                           </li>
                                           <li class="digg_s">
    												<a href="http://digg.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>">
                                                    	Digg
    												</a>
                                                    <span>Digg.com - Digg It!</span>
                                           </li>
                                           <li class="delicious_s">
                                                   <a href="http://del.icio.us/post?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>">
                                                           Delicious
                                                   </a>
                                                   <span>Del.icio.us - Add to Delicious</span>
                                           </li>
                                           <li class="reddit_s">
                                                   <a href="http://www.reddit.com/submit?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>">
                                                           Reddit
                                                   </a>
                                                   <span>Reddit.com - Add to Reddit</span>
                                           </li>
                                           <li class="technorati_s">
                                                   <a href="http://www.technorati.com/faves/?add=<?php the_permalink(); ?>">
                                                           Technorati
                                                   </a>
                                                   <span>Technorati.com - Add to Technorati</span>
                                           </li>
                                           <li class="newsvine_s">
                                                   <a href="http://www.newsvine.com/_tools/seed&save?u=<?php the_permalink(); ?>&h=<?php the_title(); ?>">
                                                           Newsvine
                                                   </a>
                                                   <span>Newsvine.com - Add to Newsvine</span>
                                           </li>
                                           <li class="design_float_s">
                                                   <a href="http://www.designfloat.com/submit.php?url=<?php the_permalink(); ?>&title=<?php the_title(); ?>">
                                                           Design Float
                                                   </a>
                                                   <span>Design Float.com - Float It!</span>
                                           </li>
                                   </ul>
                           </div>
    
                                   <div class="postmetadata top-border">
    
                                                   This entry was posted on  <?php the_time('l, F jS, Y') ?> and is filed under <?php the_category(', ') ?>. You can follow responses to this entry through this post's <span class="rss_inline"><?php comments_rss_link('RSS 2.0'); ?></span> feed.
    
                                                   <?php if (('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
                                                           // Both Comments and Pings are open ?>
                                                           You can <a href="#respond">leave a response</a>, or <a href="<?php trackback_url(); ?>" rel="trackback">trackback</a> from your own site.
    
                                                   <?php } elseif (!('open' == $post-> comment_status) && ('open' == $post->ping_status)) {
                                                           // Only Pings are Open ?>
                                                           Responses are currently closed, but you can <a href="<?php trackback_url(); ?> " rel="trackback">trackback</a> from your own site.
    
                                                   <?php } elseif (('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
                                                           // Comments are open, Pings are not ?>
                                                           You can skip to the end and leave a response. Pinging is currently not allowed.
    
                                                   <?php } elseif (!('open' == $post-> comment_status) && !('open' == $post->ping_status)) {
                                                           // Neither Comments, nor Pings are open ?>
                                                           Both comments and pings are currently closed.
    
                                                   <?php } edit_post_link('Edit this entry.','',''); ?>
    
                                   </div>
    
                           </div><!-- END ENTRY -->
                   </div><!-- END POST -->
    
                   <div class="post_nav clear">
                           <div class="alignleft"><?php previous_post_link('< %link') ?></div>
                           <div class="alignright"><?php next_post_link('%link >') ?></div>
                   </div>
    
       </div>
    </div>
    <!-- END MAIN PRIMARY -->
    
    <!-- MAIN SECONDARY	 -->
    <div id="main_secondary" class="clear">
    
           <?php comments_template(); ?>
    
    </div>
    <!-- END MAIN SECONDARY -->
           <?php endwhile; else: ?>
    
                   <p>Sorry, no posts matched your criteria.</p>
    
    <?php endif; ?>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>
  2. brianfeister
    Member
    Posted 5 years ago #

    The plot thickens!

    When I Commented out the existing call to the_loop and added the most basic version I got both "Sorry, doesn't match query" error as well as the actual post.

    This is because commenting out the first one failed if I understand correctly... The weird thing is that when I delete the page and put just the_loop I still get the "Sorry" error.

    So somehow the post content is only displaying the second time and only if the loop is called twice!

  3. brianfeister
    Member
    Posted 5 years ago #

    Resolved! Wow, I should be a web designer or something :P

    Anyway, if you have this problem and can't find any other explanation for it, check to make sure you're not calling the_loop twice... the second call will fail which is why I was getting the "Sorry, query returned no results" error.

  4. Yup, the main loop should only be called once. But you can have other loops inside the main loop by using a new query, i.e., this will show the permalink to the most recent post in mycategory:

    <?php $my_query = new WP_Query('category_name=mycategory&showposts=1'); ?><?php while ($my_query->have_posts()) : $my_query->the_post(); ?><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a><?php endwhile; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic