• Resolved gulliver

    (@gulliver)


    I’m trying – and failing – to add a conditional tag to the excerpts in my search results… so that if the excerpt is from a post it displays the post date and permalink, whereas if the excerpt is from a page it only displays the permalink and not the date.

    Displaying the appropriate meta info is straightforward, but it’s the conditional code that I’m struggling with, having experimented with various permutations of if (is_single()), if (is_page()), and echo.

    Help appreciated. Please/thanks/etc.

Viewing 1 replies (of 1 total)
  • Thread Starter gulliver

    (@gulliver)

    UPDATE: I’ll answer my own post in case it helps somebody else later.

    I’ve used this (much of which somebody elsewhere supplied):

    <?php if(get_post_type() == 'page'): // If a page. ?>
    <p><a href="<?php the_permalink(); ?>" title="permalink">Permalink</a>.</p>
    
    <?php elseif(get_post_type() == 'post'): // If a post. ?>
    <p><a href="<?php the_permalink(); ?>" title="permalink">Added</a> <?php the_time('F j, Y') ?>.</p>
    <?php endif; ?>

    An option is to replace ‘Permalink’ (for page) with <?php echo get_the_title(); ?>, or leave blank.

Viewing 1 replies (of 1 total)

The topic ‘Conditional inside search result excerpt.’ is closed to new replies.