WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] remove date/time from entry if it is a page, in search results (6 posts)

  1. overflow
    Member
    Posted 5 years ago #

    My search.php loops whatever returns the ?s= query

    I'd like to edit my search.php further so that if the entry being displayed is a page, the date/time is not shown.

    How do I detect, from inside the loop, if the currently being dumped entry is a page, to code accordingly?

    Many thanks in advance!

  2. MichaelH
    Member
    Posted 5 years ago #

    See Conditional Tags and the is_page() conditional.

  3. overflow
    Member
    Posted 5 years ago #

    Yes, I tried that... it's like this:

    <div id="container">
    <?php if(have_posts()) : ?>
    <?php while(have_posts()) : the_post(); ?>
    <div class="post" id="post-<?php the_ID(); ?>">
    
    <div class="post_header">
    
    <?php if( is_page() ) { echo "PAGE!"; } ?>
    
    <h2>" title="<?php the_title(); ?>">
    <?php the_title(); ?></h2>

    In concrete the part

    <?php if( is_page() ) { echo "PAGE!"; } ?>

    But it never shows the PAGE! string as I wished...

    As far as I understood, the is_page() is to detect if the current big render is a page... in this case it is a search.

  4. overflow
    Member
    Posted 5 years ago #

    the code ticks don't work so well apparently, the code i pasted ended up a bit messed up, but i think u get the idea. thanks!

  5. MichaelH
    Member
    Posted 5 years ago #

    Probably cause it's a search page...

    See if this works:

    if ($post->post_type=='page') {
    echo 'page';
    }
  6. overflow
    Member
    Posted 5 years ago #

    Yes! Exactly what I wanted :) Thanks a lot!

Topic Closed

This topic has been closed to new replies.

About this Topic