• Hi,

    I’m sort of new to WordPress, but learning fast. πŸ™‚ I’m working on a somewhat complicated site, and the codex has gotten me pretty far, but I’m having some trouble.

    I have a left sidebar on the site. Say I want to use a loop to put an excerpt or a list of posts on the left. I used a loop and set it to display just one category. When I do this, it messes up my page content and displays the category of posts that I used on the sidebar in my content area. How do I “reset” what posts I have called for the sidebar so that I can call my page content for the content area?

    Also, I have set a page for the homepage of the website. The site has two different blog-like sections, but they are both currently working as pages. What should I do with index.php (if anything)?

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • If your using a custom query before the main loop you need to create a new query object.

    Here’s a quick example using an unordered list to output posts from a query object:

    <ul class="side-posts">
    <?php
        $sidebar_query = new WP_Query("cat=42&showposts=10");
        $wp_query->in_the_loop = true;
        while ($sidebar_query->have_posts()) : $sidebar_query->the_post();
    ?>
            <li id="side-post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
        <?php endwhile; ?>
    </ul>

    Where cat=42 you should replace with your category number. Showposts=10 controls how many posts to display. Hope that gets you started.

    Thread Starter digitaljohn

    (@digitaljohn)

    I’m having no problem displaying the posts from the categories I want to display. I can’t figure out the code to display page content after I’ve called a post category on the left sidebar (higher in the structure).

    In the example above try changing this line:

    $sidebar_query = new WP_Query("cat=42&showposts=10");

    to

    $sidebar_query = new WP_Query('page_id=2');

    where 2 is the id of your page.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Loop Issues’ is closed to new replies.