• I’m trying to remove query_posts() following the advice here on the WordPress Codex but it’s not working for me. If I try the advice in those instructions, the first page of my blog returns only one post instead of the five that I specify.

    If I only add the “pre_get_posts” to my functions.php,it works …however it is still using get_posts() …which is inefficient. I think the reason is that there is a previous call to get_posts in my index.php which I’m not replacing. That call is simply getting a list of categories. See code below …with the first and second calls to query_posts() shown in bold. I’m primarily trying to replace the second one:

    <div id="middle" class="clearfloat">
    	<img src="<?php echo get_option('home'); ?>/wp-content/themes/arthemia/images/category.png" class="clearfloat" alt="" />
    	<?php $display_categories = array(5,6,7,8,11); $i = 1;
    	foreach ($display_categories as $category) { ?>
    
    	<div id="cat-<?php echo $i; ?>" class="category">
    		<?php <strong>query_posts("showposts=1&cat=$category")</strong>?>
    		<span class="cat_title"><a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?></a></span>
    		<a href="<?php echo get_category_link($category);?>"><?php echo category_description($category); ?></a>
    	</div>
    
    	<?php $i++; ?>
        	<?php } ?>
    
    	</div>
    
    	<?php } ?>
    
    	<div id="bottom" class="clearfloat">
    
    	<div id="front-list">	
    
    	<?php
          $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
          <strong>query_posts("cat=-27,-28&paged=$page&posts_per_page=5");</strong> ?>
    
    	<?php while (have_posts()) : the_post(); ?>

    How can I make this work?

Viewing 1 replies (of 1 total)
  • Thread Starter patrick_here

    (@patrick_here)

    Okay, I’ve managed to eliminate that first call to query_posts() but my index.php still has a prior call to query_posts() that I can’t remove because it uses a custom taxonomy that I defined and I’m passing the custom taxonomy as an argument to query_posts(). It looks like this:

    <?php $args = array('homepageposts' => 'Featured'); query_posts($args); ?>
    <?php while (have_posts()) : the_post(); ?>

    I think I need to get rid of all of the calls to query_posts() because prior calls to query_posts() will mess up the subsequent sections where I’m trying to eliminate them. Any advice as to what to do about this call to query_posts() of a specific taxonomy?

Viewing 1 replies (of 1 total)
  • The topic ‘Removing query_posts()’ is closed to new replies.