• Resolved danalydesign

    (@danalydesign)


    So I have this chunk of code in my right sidebar. I want to hise the entire module if there are no posts found instead of displaying “no posts found”. How would I go about doing this? Please incorporate your code into mine below if possible. i really appreciate any assistance you awesome wordpressers can provide!

    <div id="popularApps" class="module">
        <h3>Popular Sleep Apps</h3>
        <div class="moduleContent">
          <?php $query = array ( 'post_type' => 'affiliates', 'affiliatetype' => 'apps', 'category__in' => $post_categories, 'posts_per_page' => 3 ); ?>
          <?php $queryObject = new WP_Query($query); ?>
          <?php if ($queryObject->have_posts()) : while ($queryObject->have_posts()) : $queryObject->the_post(); ?>
          <div class="entry"><a href="/affiliates/<?php echo basename(get_permalink()); ?>/"><?php echo get_the_post_thumbnail( get_the_ID(), array(43,43)); ?>
            <p><?php if (strlen($post->post_title) > 24) { echo substr(the_title($before = '', $after = '', FALSE), 0, 24) . '...'; } else { the_title();} ?></p></a>
            <div class="clear"></div>
          </div>
          <?php endwhile; else: ?>
          <p>No Apps are available at this time</p>
          <?php endif; ?>
          <?php wp_reset_query(); ?>
        </div>
        <div class="moduleFooter"><a href="/affiliates/apps/">View More</a>
          <div class="clear"></div>
        </div>
      </div>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try it with this:

    <?php $query = array ( 'post_type' => 'affiliates', 'affiliatetype' => 'apps', 'category__in' => $post_categories, 'posts_per_page' => 3 ); ?>
     <?php $queryObject = new WP_Query($query); ?>
     <?php if( $queryObject->have_posts() ) : ?>
    <div id="popularApps" class="module">
        <h3>Popular Sleep Apps</h3>
        <div class="moduleContent">
          <?php if ($queryObject->have_posts()) : while ($queryObject->have_posts()) : $queryObject->the_post(); ?>
          <div class="entry"><a href="/affiliates/<?php echo basename(get_permalink()); ?>/"><?php echo get_the_post_thumbnail( get_the_ID(), array(43,43)); ?>
            <p><?php if (strlen($post->post_title) > 24) { echo substr(the_title($before = '', $after = '', FALSE), 0, 24) . '...'; } else { the_title();} ?></p></a>
            <div class="clear"></div>
          </div>
          <?php endwhile; else: ?>
          <p>No Apps are available at this time</p>
          <?php endif; ?>
        </div>
        <div class="moduleFooter"><a href="/affiliates/apps/">View More</a>
          <div class="clear"></div>
        </div>
      </div>
     <?php endif; ?>
     <?php wp_reset_query(); ?>

    Thread Starter danalydesign

    (@danalydesign)

    keesiemeijer, no matter what anyone saysd about you – I know that you ARE the man! Thanks for keeping me sane!

    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome. I’m glad you’ve got it resolved 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Hide code if no posts are found?’ is closed to new replies.