WordPress.org

Ready to get started?Download WordPress

Forums

help with WP_Query code (2 posts)

  1. goldmember
    Member
    Posted 1 year ago #

    on this page i have this code which pulls in the Upcoming Events category post titles:

    <h2>Gold Coast Chamber Upcoming Events</h2>
    Coming Soon...
    <?php
      $loop = new WP_Query( array(
        'category_name' => 'Events',
        'orderby' => 'meta_value',
        'meta_key' => 'eventdate',
        'order' => ASC)
      );
      while ( $loop->have_posts() ) : $loop->the_post(); ?>
      <div class="sing-event">
        <p class="up-events"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <div id="teaser"><img src="<?php $thumb = get_post_custom_values('teaser'); echo $thumb[0]; ?>" alt="<?php the_title(); ?>" /></div></div>
    <?php endwhile; ?>

    We don't have any posts from that category at the moment so I inserted the text "Coming Soon..." but i'm wondering how I could fit that Coming Soon... into the code so that it gets auto-generated when there's no posts in that category.

    any idea? please advise. thanks in advance!

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    get inspired by the default loop structure:

    http://codex.wordpress.org/The_Loop_in_Action

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags