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 6838589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:36:55+00:00 2026-05-26T23:36:55+00:00

I am trying to create a single php file I can use to display

  • 0

I am trying to create a single php file I can use to display the content for the index or a page in wordpress. This question is not wordpress specific though.

I have a ‘while’ which needs to be closed in two different places depending on whether the index or a page is being displayed. I am trying to close the ‘while’ with an ‘if’

if (is_home()) { endwhile; }
// otherphp
if (is_page()) { endwhile; }

This is not working though. The full code is below:

<section id="main">
  <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
  <?php if (is_home()) : ?> <article <?php post_class() ?> id="post-<?php the_ID(); ?>"> <?php elseif (is_page()) : ?> <article class="post" id="post-<?php the_ID(); ?>"> <?php else : NULL; endif; ?>
    <div class="entry">
      <?php the_content(); ?>
    </div>
  </article>
  <?php if (is_home()) { endwhile; } ?> <!-- ENDWHILE MUST BE HERE ON INDEX PAGE -->
  <?php if (is_home()) : get_template_part('nav','default'); elseif (is_page()) : NULL; else : NULL; endif; ?>
  <?php if (is_page()) { endwhile; } ?> <!-- ENDWHILE MUST BE HERE ON ALL OTHER PAGES -->
  <?php endif; ?>
</section>

I realise this code is somewhat inefficient and messy but at the moment I am not concentrating on efficiency. I am simply trying to make it work.

How can I conditionally end the ‘while’?

  • 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-26T23:36:55+00:00Added an answer on May 26, 2026 at 11:36 pm

    Just do a normal condition inside a normal while:

    while (/* something */) :
    
        // same for all
    
        if (/* is home */) {
            // do something only for home
        }
    endwhile;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a use-once HTTP server to handle a single callback and
I'm trying to use PHP to create a shell script on Windows. It's part
I'm trying to create an if statement in PHP that prevents a single post
I'm trying to create a single instance Qt application and I'm at the point
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying to create a single sign on process. The method I have
Sorry for this question. Basically I have a page where I have it automatically
I'm trying to use mongodb with PHP. For that, I have created a MongoHQ
So I currently use the following: $.ajax({ type: GET, url: file.php, success: function(html) {
I am trying to create a single-choice (e.g., radio button) list of items that

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.