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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:16:25+00:00 2026-05-14T14:16:25+00:00

I’ve edited the single.php to suit my needs and it works. I only left

  • 0

I’ve edited the single.php to suit my needs and it works. I only left in the part of the loop in in which is as follows:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
        <div class="entry">
        <?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>
        <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>     </div>
    </div>
<?php endwhile; else: ?>

    <p>Sorry, no posts matched your criteria.</p>

<?php endif; ?>

It only displayes the text, like I want it to.
The problem I get is when I add the following code to be used as the sidebar in the template;

<?php query_posts('showposts=10'); ?>
 <?php while (have_posts()) : the_post(); ?> 
<a href="<?php the_permalink() ?>" rel="bookmark" title="Link to <?php the_title(); ?>">
<?php the_title(); ?></a><br /> 
<?php endwhile;?> 

It should display the title of the last 10 posts. But now the loop also is displaying the latest (full0 10 posts instead of just the one post that belongs to the permalink… I think a variable or so is being reused and needs to be rest.. Note that in the single.php first you get the ‘sidebar’ code, and then you get the ‘loop’ code.

So why is wordpress behaving this way?

  • 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-14T14:16:26+00:00Added an answer on May 14, 2026 at 2:16 pm

    The reason this happens is because WordPress is a nightmarish maze of global variables. query_posts() is one of the worst offenders. If you check the documentation for this function, you’ll see that they even have to warn you to basically not use it:

    Important note

    The query_posts function is intended
    to be used to modify the main page
    Loop only. It is not intended as a
    means to create secondary Loops on the
    page. If you want to create separate
    Loops outside of the main one, you
    should create separate WP_Query
    objects and use those instead. Use of
    query_posts on Loops other than the
    main one can result in your main Loop
    becoming incorrect and possibly
    displaying things that you were not
    expecting.

    They’ve added some object oriented stuff that you can use now instead, namely the WP_Query object (why they haven’t revamped the “main” pages to get rid of the ridiculous “The Loop” stuff yet is questionable).

    You’re going to want to do something like this in the sidebar:

    <?php
    $recentPosts = new WP_Query();
    $recentPosts->query('showposts=10');
    while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
    
    <a href="<?php the_permalink() ?>" rel="bookmark"
        title="Link to <?php the_title(); ?>">
    <?php the_title(); ?></a><br /> 
    <?php endwhile;?> 
    

    Google around about how to use WP_Query if you want more examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.