• I want to get some code going so I can have recent posts show up in the sidebar. I’d use the sidebar widget, but when I go to use it, it messes the formatting of everything up. So, I just wanted to add the coding directly to the main index page, but I don’t know what the code is.

Viewing 15 replies - 16 through 30 (of 33 total)
  • Thread Starter mithrustt

    (@mithrustt)

    So close! It looks great now, but there is one more problem. I have three posts, all of which are in the same caetegory, which is the category I have set up to show under recent posts.

    However, it only shows the two in the sidebar and on the main page. When I enter the URL for the third post, it still doesn’t show up. But when I take the recent posts code out, it shows up fine.

    What could be causing this?

    Thread Starter mithrustt

    (@mithrustt)

    Actually, I did have it in the wrong category, so I switched it and it shows up. However, when I made a test post in a different category, it doesn’t show up at all.

    Great, so far :).

    Well, look at the line with query_posts… see the "cat=5" in there as an option? That means, that only posts from category 5 (= reviews?) are being displayed. If you want to include other categories to the query (let’s say, category 1), you would modify your query_posts like this:

    query_posts('cat=1,5&showposts=5');

    Now it says: “Ask for the 5 latest posts from categories 1 and 5.”
    You can add as many categories as you like. Example:

    query_posts('cat=1,4,5,10,12&showposts=5');

    Thread Starter mithrustt

    (@mithrustt)

    I understand that, but the problem is that it doesn’t display a post on the main page if it isn’t included in the query_posts.

    Thread Starter mithrustt

    (@mithrustt)

    And it also won’t display pages. I’ll click on a page link, and it says it goes there, but it just shows the home page.

    That’s odd… and shouldn’t be. Are you sure, you didn’t forget this line before our "while..."
    <?php $myquery = $wp_query; ?>
    …and this one below our "endwhile"…?
    <?php $wp_query = $myquery; ?>

    If they are both there, I don’t think this loop has something to do with the not appearing post on your main page.

    Thread Starter mithrustt

    (@mithrustt)

    This is what I have:

    <h2>Recent Reviews</h2>

    <br/>

    Seems fine to me. If you delete the whole thing (the code you just posted), does the rest of your page work as it should?

    I’m using something very similar on my page, and it doesn’t give me any problems. Maybe someone else has an idea?

    Oh, and please use the backticks (“code”-button) for code you post (explanation below the text area) :).

    Thread Starter mithrustt

    (@mithrustt)

    Yeah, everything works perfectly normal when the new code is gone.

    I don’t understand.

    In the end, immediately after ′<?php $wp_query = $myquery; ?>` try inserting the following line:

    <?php rewind_posts() ?>

    Thread Starter mithrustt

    (@mithrustt)

    Nope, that didn’t work.

    Ok, delete the rewind_posts() line. Then modify:

    <?php $myquery = $wp_query; ?>
    to -> <?php $myquery = clone $wp_query; ?>

    and

    <?php $wp_query = $myquery; ?>
    to -> <?php $wp_query = clone $myquery; ?>

    Now pray, that it works with wordpress 2.2! ??

    Thread Starter mithrustt

    (@mithrustt)

    No, it gives me this error:

    arse error: syntax error, unexpected T_VARIABLE in /home/thinkth1/public_html/savingprogress/launchprep/wp-content/themes/blueblog-10/sidebar.php on line 50

    Ok, one last thing before I give up…

    Delete:
    <?php $myquery = $wp_query; ?> (or the modified one with clone)
    and…
    <?php $wp_query = $myquery; ?> (or the modified one)

    Replace:
    <?php query_posts('cat=5&showposts=5'); ?> with…
    <?php $myquery = new WP_Query('cat=5&showposts=5'); ?>
    and…
    <?php while (have_posts()) : the_post() ?> with…
    <?php while($myquery->have_posts()) : $myquery->the_post(); ?>

    But I have no idea, if the loop shows the correct titles/links, regardless of what else is currently displayed on your page.

    Thread Starter mithrustt

    (@mithrustt)

    You are probably the smartest person alive. It works perfectly!

    THANK YOU SO MUCH!

Viewing 15 replies - 16 through 30 (of 33 total)
  • The topic ‘Recent Posts Code’ is closed to new replies.