Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7702489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:14:20+00:00 2026-05-31T23:14:20+00:00

I am using WP_Query to loop through a custom post type in wordpress. My

  • 0

I am using WP_Query to loop through a custom post type in wordpress. My loop looks like this:

<div class="bigRedStrip">
    <h2>Available Now!</h2>
</div>

<ul>
    <?php $loop = new WP_Query( array( 'post_type' => 'films', 'post_child' => 0, 'posts_per_page' => 8,'orderby' => 'date', 'order' => 'ASC', 'film-categories' => 'blu-ray' ) ); ?>

    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

            <li>
             loop stuff here
            </li>

    <?php endwhile; ?>
</ul>

As you can see, before the loop there is a header that says “Available Now!”. I want to reformat the loop so if there are no posts returned, then the div containing the title (div class bigRedStrip) will not be displayed. I have tried a number of potential solutions, but the problem I keep running into, is that all of these “solutions” require putting the <div class="bigRedStrip"> inside the loop, which results in the header repeating for every returned post. The idea is to have the header only displayed once. Any ideas how I can accomplish this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:14:21+00:00Added an answer on May 31, 2026 at 11:14 pm

    You only need to pull the things a bit apart. First of all run the query:

    <?php $loop = new WP_Query( array( 'post_type' => 'films', 'post_child' => 0, 'posts_per_page' => 8,'orderby' => 'date', 'order' => 'ASC', 'film-categories' => 'blu-ray' ) ); ?>
    

    Then check if there is something:

    <?php if ($loop->have_posts()) { ?>
    
    <div class="bigRedStrip">
        <h2>Available Now!</h2>
    </div>
    
    ...
    

    And if so, just iterate over the posts:

    ...
    
    <ul>
        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
                <li>
                 loop stuff here
                </li>
    
        <?php endwhile; ?>
    </ul>
    
    <?php } ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a WP_Query to query my custom post type posts. This custom post
I am using a custom post type in my wordpress theme, and I need
I store post IDs in an array. I would like to loop through the
I'm using this piece of code I found ( http://impnerd.com/wordpress-hack-add-post-images-to-your-homepage ) to display the
I've created a custom post type in WordPress, and in the single post template,
On my homepage I am bringing in some custom post types using this: <?php
Using Flex 3, I would like to take an image snapshot such as this:
Is it possible to loop in a wordpress plugin? I've created this plugin that
I am trying to display results of a custom post type on my main
I use WP plugin Custom Post Type UI and a template of my own

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.