WordPress.org

Support

Support » Themes and Templates » [Resolved] Check if post in search results loop

[Resolved] Check if post in search results loop

  • My <?php if(is_single()){ ?> line doesn’t do anything. If I put an }else{ on it, it always shows the else result. I want to check if the item in the search result is a post or a page. I only want to show category and date meta info if it is a post. Doesn’t make since to show that if its a page.

    <?php if (have_posts()) : ?>
    
    			<h2 class="pagetitle">Search Results</h2>
    
    			<div class="navigation">
    				<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    				<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    			</div>
    			<div class="clear"></div>
    
    			<?php while (have_posts()) : the_post(); ?>
    
    				<div <?php post_class() ?>>
    					<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
    
    					<?php if(is_single()){ ?>
    					<p class="postmetadata">
    					<small><?php the_time('l, F jS, Y') ?></small>
    					<br />
    					Posted in <?php the_category(', ') ?></p>
    					<?php } ?>
    				</div>
    
    			<?php endwhile; ?>
    
    			<div class="navigation">
    				<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    				<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    			</div>
    
    			<?php else : ?>
    
    				<h2 class="center">No posts found. Try a different search?</h2>
    				<?php get_search_form(); ?>
    
    			<?php endif; ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Check if post in search results loop’ is closed to new replies.
Skip to toolbar