WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Check if post in search results loop (5 posts)

  1. Darrell Schauss
    Member
    Posted 4 years ago #

    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; ?>
  2. esmi
    Forum Moderator
    Posted 4 years ago #

    Try changing:

    <?php if(is_single()){ ?>

    to:

    <?php if(!is_page()){ ?>

  3. Darrell Schauss
    Member
    Posted 4 years ago #

    Ok I tried that and it always shows the meta then. I have a specific word that will give me a result of Page and a Post. Both behave the same. I have a feeling its checking the search page itself with the condition?

  4. esmi
    Forum Moderator
    Posted 4 years ago #

    Got it! <?php if($post->post_type == 'post') :?>

  5. Darrell Schauss
    Member
    Posted 4 years ago #

    That works.

Topic Closed

This topic has been closed to new replies.

About this Topic