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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:18:48+00:00 2026-06-18T06:18:48+00:00

Im having a problem where for some reason, a basic loop im trying to

  • 0

Im having a problem where for some reason, a basic loop im trying to add to a sidebar keeps….keeps looping on interior pages (single and page .php ) but not on index.php.

on index.php (home page) is fine.

for example, i wanted the loop to populate an unordered lists line items, so i went about it like this:

      <div id="sideBarMain">
        <h2>title4sidebar</h2>
       <ul>     
             <?php 
            query_posts( array ( 'category_name' => 'left_sidebar', 'posts_per_page' => 4, 'orderby=menu_order' ) );
            if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
            <li><a href="<?php the_permalink();  ?>"><?php the_title(); ?></a></li>
            <?php endwhile; endif; ?>
        </ul>

      </div><!-- sidebar ender -->

A few things are happening.
1. the MOST problematic is that when this loop is in place, it breaks the navigation and all. i click on a page and the page loads up with one of the list line items on the header…so if i click “about us” on the main nav, a page loads with “line item title” instead…..

also happens on any item clicked.

2 – is that on the (page/single.php pages), on the sidebar, it will post the first 4 posts with the category “left_sidebar” how it should be displayed, css in place and all but after the fourth line item, it will repeat the loops one more time.

3 – My sites content area has 2 columns, the sidebar on the left, and the main content area on the middle. On the part that’s being wrongfully repeated (after the loops repeats), when i checked with FireBug, on the repeated line items, its also taking the H tag properties from i assume, an h-tag thats next to it on another column. So the first 4 line-items come out fine with the styles given to them via CSS, link colors, rollovers etc, and the next buggy 4 line items come out un-styled, permalink also isnt being applied to them like the first 4 etc.

3 – i removed all html from that php loop like the divs and ul / lis etc so no css is being applied, this way only text come up from the loop but the same thing happens, Since i removed the html portion of the loop, the first 4 li’s come up with the standard default blue link text etc, and the following buggy 4 come up the same as before all big with htags attached….

Troubleshooting it all,
– theres only one loop on the page which stems from the sidebar.
– ive properly cleared all floats
– when checking on W3C for errors etc, there are none. green lights through and through.
– no errors on the php side of things. (ive checked every page and have errors enabled) on local server.

im lost.

Any ideas as to what can be happening?

NOTE: thinking ahead, although there is one loop ONLY on the sidebar.php page, once imported technically theres 2 loops which i guess is the sidebar wp loop, and the page.php / single.php loops which get the content.

is there anything different as of the latest wp maybe? Ive always done it like this and now i have problems……

any ideas? im lost.

Thanks in advanced.

  • 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-06-18T06:18:50+00:00Added an answer on June 18, 2026 at 6:18 am

    Your problem is two-fold:

    1) It is imperitive you stop using query_posts. There are many well-documented reasons as to why using this function needs to end, but I think this is the best explanation.

    2) You aren’t resetting your query. More on that in a minute.

    Going back to number 1, the problem with query_posts is that it affects the global $wp_query object. This would be fine if your intention was to modify the main loop, but that’s not what you’re trying to do here. What you need to use is WP Query. The syntax in creating a new Query Object is identical to query_posts, but the benefit is that you are no longer affecting the global instance of $wp_query.

    Resetting your query also ensures that no other sections of code utilizing a WordPress Query are going to be affected by your Query Object.

    Try changing your code example to this:

    <?php 
    $query = new WP_Query(array('category_name'=>'left_sidebar','posts_per_page'=>4,'orderby=menu_order'));
    if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
    ?>
    <li><a href="<?php the_permalink();  ?>"><?php the_title(); ?></a></li>
    <?php
    endwhile;endif;
    wp_reset_postdata();
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason I'm having a problem retrieving data from my database. It leaves
I'm having a problem instantiating a ListItem object with specified attributes. For some reason
I am having a problem with the code below. For some reason it displays
For some reason I'm having a problem retrieving data from my database. It leaves
Having a problem getting the URL for a resource for some reason: This code
I'm having a problem instantiating an anonymous type in my code. For some reason,
I am having a problem where for some reason in IE the background at
im having a problem converting time. for some reason it seems to be defaulting
I am having a problem with Scrapy, for some reason it is not entering
I am having a problem updating a record. For some reason it is not

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.