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

  • SEARCH
  • Home
  • 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 6869401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:33:11+00:00 2026-05-27T03:33:11+00:00

I am using an if elseif statement to check what page it is, and

  • 0

I am using an if elseif statement to check what page it is, and it requires that there are posts on the page so when a search is returned with a result of 0, my code stops working. Any ideas how to code this better?

this code is in my sidebar and is showing the recent articles, you can see an example of a search working here(the sidebar is setup as a sub-footer):
http://ivry.sweetyams.ca/?s=new

and a search not working here:
http://ivry.sweetyams.ca/?s=asjdfkl%3B

Code I am using:
(I have tried putting stuff into the else{ code and it doesn’t work either because there are no posts on the ‘nothing found’ search page

<?php if (have_posts()) : ?>
<?php /* IF SEARCH PAGE */  if (is_search() ) { ?>
  <?php query_posts('category_name=0&showposts=5'); ?>
  <?php while (have_posts()) : the_post(); ?>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
        <p> <?php the_title(); ?></p>
        </a>
  <?php endwhile;?>

<?php /* IF ESCALADE PAGE */ }elseif (is_category_or_sub(6)) { ?>
  <?php query_posts('category_name=escalade&showposts=5'); ?>
  <?php while (have_posts()) : the_post(); ?>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
        <p> <?php the_title(); ?></p>
        </a>
  <?php endwhile;?>

<?php /* IF MONTAGNE PAGE */ } elseif (is_category_or_sub(14)) { ?>
  <?php query_posts('category_name=montagne&showposts=5'); ?>
  <?php while (have_posts()) : the_post(); ?>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
        <p> <?php the_title(); ?></p>
        </a>
  <?php endwhile;?>

<?php } else { ?>
DO SOMETHING ELSE
<?php }?>
<?php endif; ?>`

I am trying to get all recent articles for my sidebar and when there is no result in the search, it also stops my sidebar from working.

The code I added is not in my search page but in my SIDEBAR, it separates the comments into 2 categories, (6 and 14) I am essentially splitting my site using categories for navigation, anything as a child below 6 will be styled one way and 14 the other, you can see the difference on the escalade and montagne links:

This is getting every post below escalade, OR every post below the montagne category

My search pulls results from ALL categories, but if there is no search result, for some reason my sidebar code, the code I included, doesn’t work.

  • 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-27T03:33:12+00:00Added an answer on May 27, 2026 at 3:33 am

    I found a way to get it to work,

    I found that it is encouraged to use WP_Query for secondary posts within a page, http://new2wp.com/noob/query_posts-wp_query-differences/

    also, for anyone that is wondering the is_category_or_sub function is from here: http://valendesigns.com/wordpress/is-category-or-subcategory-wp-function/

    This code checks whether you are on a category or subcategory,

    <?php
    $my_posts = new WP_Query(); ?>
    
    <?php /* IF ESCALADE PAGE */ if (is_category_or_sub(6)) { ?>
        <?php $my_posts->query('posts_per_page=5&cat=6');?> 
    
    <?php /* ELSEIF MONTAGNE PAGE */ } elseif (is_category_or_sub(14)) { ?>
        <?php $my_posts->query('posts_per_page=5&cat=14'); ?>
    
    <?php } /* AND OTHER PAGE */ else { ?>
        <?php $my_posts->query('posts_per_page=5'); ?>
    <?php }?>
    
    <?php while ($my_posts->have_posts()) : $my_posts->the_post(); // loop for posts ?>
        <a href="<?php echo esc_url( get_permalink( $post->the_permalink ) ) ?>" title="Permanent Link to <?php echo substr($post->post_title,0,200);?>">
        <p><?php echo substr($post->post_title,0,200); ?></p>
        </a>
    
    <?php endwhile; ?>
    <?php wp_reset_query() // RESET QUERY ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using ASP.NET MVC there are situations (such as form submission) that may require a
I'm currently working on a project using the current if statement and i'm sure
I have a string that is 141 characters in length. Using the following code
i would like to ask if there is an elseif statement in blogger? All
I am using the following code to compare types so that a DataContractSerializer will
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using C#, I need a class called User that has a username, password, active
Using preview 4 of ASP.NET MVC Code like: <%= Html.CheckBox( myCheckBox, Click Here, True,
I am currently implementing a simulation in Java that requires an input of about

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.