WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Using 'query_posts' parameters in author.php (2 posts)

  1. Hedley
    Member
    Posted 5 years ago #

    My author.php correctly displays information from the user record and a list of titles of that users posts. This is good. Now I want to limit the post titles that are displayed by excluding two categories, and I also want to force it to display all post titles, instead of the globally set ten posts.

    To my author.php I added (right at the start of the loop): <?php query_posts('showposts=9999&cat=-30,-32'); ?>. It works, in the sense that it excludes the two categories and removes the 10 post limit, BUT, it displays posts from ALL users, not just the one specified in the curauth variable (yet still displays the curauth data for the correct user).

    I assume that use of 'query_posts' is overriding the post selection somehow, but I'm at a loss where and how. Can anyone spot the flaw in my usage? Here's my entire author.php.

    Thanks!

    <?php get_header(); ?>
       <div id="content" class="narrowcolumn">
          <!-- This sets the $curauth variable -->
    <?php
    if(isset($_GET['author_name'])) :
    $curauth = get_userdatabylogin($author_name);
    else :
    $curauth = get_userdata(intval($author));
    endif;
    ?>
    
    <h2>About: <?php echo $curauth->nickname; ?></h2>
    <dl>
    <dt>Website</dt>
    <dd><a href="<?php echo $curauth->user_url; ?>"><?php echo $curauth->user_url; ?></a></dd>
    <dt>Profile</dt>
    <dd><?php echo $curauth->user_description; ?></dd>
    </dl>
    
    <h2>Posts by <?php echo $curauth->nickname; ?>:</h2>
    
    <ul>
    <!-- The Loop -->
    <?php query_posts('showposts=9999&cat=-30,-32'); ?><?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
      <li>
    <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>">
    <?php the_title(); ?></a>,
    <?php the_time('d M Y'); ?> in <?php the_category('&');?>
      </li>
    
      <?php endwhile; else: ?>
         <p><?php _e('No posts by this author.'); ?></p>
    
    	<?php endif; ?>
    <!-- End Loop -->
    </ul>
    </div>
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
  2. harjeet singh
    Member
    Posted 4 years ago #

    Try replacing

    <?php query_posts('showposts=9999&cat=-30,-32'); ?>

    with

    <?php query_posts($query_string.'&showposts=9999&cat=-30,-32'); ?>

    Just added "$query_string." and "&" before showposts.

Topic Closed

This topic has been closed to new replies.

About this Topic