WordPress.org

Ready to get started?Download WordPress

Forums

Adding Additional Archived Content in Search Results (Archive Posts) (1 post)

  1. guitargeek_com
    Member
    Posted 3 years ago #

    My WordPress site search results are working great. I'm attempting to add a list of archived posts along with a "We didn't find anything! You might want to check out the following articles:" when the search results come back with no results.

    I've created two loops (at least I think I have!) that are working fine but the "no results + archived posts" are still appearing in the regular search results - I only want them to appear in the "No Results" results.

    Any suggestions?

    Here's my code:

    // <!-- Main Search Results -->
    <div id="front" class="primary_col">

    <?php if (have_posts()) : ?>
    <?php $count = 0; ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php $count++; ?>
    <?php if ($count == 1) : ?>

    <div id="featured">
    <div class="thumbnail">
    <?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
    </div>

    <div class="title">
    <h2><?php the_category(', '); ?><i> — <?php the_time('l, F j, Y'); ?></i></h2>
    <h1>" title="<?php the_title(); ?>"><?php the_title(); ?></h1></div>
    </div>

    <?php else : ?>
    <div class="clearandspace"></div>
    <div class="otherposts">
    <div class="thumbnail"><?php the_post_thumbnail(); ?></div>
    <div class="contents">
    <h3>" title="<?php the_title(); ?>"><?php the_title(); ?></h3>
    <h2><i><?php the_time('l, F j, Y'); ?></i></h2>
    </div>
    </div>

    <?php endif; ?>
    <?php endwhile; ?>

    <div class="clearandspace"></div>

    <div class="navigation">
    <div class="alignleft"><?php posts_nav_link('','','Previous Entries') ?><?php posts_nav_link('','Next Entries','') ?></div>
    </div>

    <!-- Alternate Search Results - With Posts -->
    <?php else : ?>
    <div class="clearandspace"></div>

    <h1>We didn't find anything!</h1>
    <p>Try narrowing your search term. If that doesn't seem to work, please make a request HERE</p>
    <div class="dash"></div>
    <h3>You might want to check out the following articles:</h3>
    <div class="dash"></div>

    <?php endif; ?>
    <div class="clearandspace"></div>

    <?php endwhile; ?>

    <!-- // Search Results -->

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 3 years ago by guitargeek_com
  • This topic is not resolved
  • WordPress version: 3.2.1