Forums

unable to get showposts to work properly (4 posts)

  1. bizchickblogs
    Member
    Posted 1 year ago #

    At http://www.overturemarketplace.com

    I'm trying to make it so that the recent posts only shows 5, but using 'showposts=5' in the code doesn't work. The guys who customized this theme used a custom query which they were able to get only 5 posts to show, but the issue is that we've added a News category and do not want news showing up under Recent Posts, so I added a more standard recent posts code which effectively removes the unwanted category, but it ignores the showposts parameter.

    Here is the code used currently:

    <h4>Recent Posts</h4>
    
    <ul>
    <?php $temp_query = $wp_query; query_posts('showposts=5&cat=-74'); //ejm exclude category 74 ?>
    <?php while (have_posts()) { the_post(); ?>
    <li><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to &ldquo;<?php the_title(); ?>&rdquo;"><?php the_title(); ?></a></li>
    <?php } $wp_query = $temp_query; ?>
    </ul>

    As you see at the page, 9 posts are showing (bizarre). Nothing is in order, either.

    Here is the code the guys who originally did the theme used, but again, this code doesn't exclude category 74 which is important.

    <?php
    									$recent_posts = $wpdb->get_results("SELECT id,post_title FROM {$wpdb->prefix}posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC LIMIT 0,5");
    									foreach($recent_posts as $post) {
    										print "<li><a href='". get_permalink($post->id) ."'>".$post->post_title."</a></li>\n";
    									}
    
    								?>

    Any thoughts? Much appreciated.

  2. alchymyth
    The Sweeper
    Posted 1 year ago #

    i can only see 5 posts in 'recent posts' in the sidebar tab.

    sorted?

  3. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    <?php $temp_query = $wp_query; query_posts('posts_per_page=5&cat=-74'); //ejm exclude category 74 ?>

  4. bizchickblogs
    Member
    Posted 1 year ago #

    Unfortunately that solution did not work.

    I ended up finding one that DID work, and the site got messed up, code got lost, and now we can't figure out how to do it again.

    What I do remember is that the temp query solution did not work. Only the one that starts with $recent_posts = $wpdb->get_results works. It's just a matter of finding out how to correctly add a parameter to exclude category 74.

Topic Closed

This topic has been closed to new replies.

About this Topic