WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pagination not Working while using query_posts (3 posts)

  1. Suresh Patel
    Member
    Posted 1 year ago #

    This is my loop.php code what i want here is remove one category to display on home page for that i used below code after adding query_posts code my pagination stop working this is the URL of my website Pixel2Pixel Design. `<?php
    if ( is_home() ) {
    query_posts( 'cat=-234' );
    }
    ?>`

    Thanks in Advance.
    Suresh

    <blockquote><ul class="entry-list group">
    
    <!-- Remove Community News Category from Homepage Start -->
    <?php
    if ( is_home() ) {
        query_posts( 'cat=-234' );
    }
    ?>
    <!-- Remove Community News Category from Homepage End -->
    
    	<?php $i = 1; echo '<li class="entry-row">'; while ( have_posts() ): the_post(); ?>
    
    	<article id="entry-<?php the_ID(); ?>" <?php post_class('entry group'); ?>>
    		<div class="entry-inner">
    			<div class="entry-thumbnail">
    				<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
    					<?php if ( has_post_thumbnail() ): ?>
    						<?php the_post_thumbnail('size-thumbnail-medium'); ?>
    					<?php else: ?>
    						<img src="<?php echo get_template_directory_uri(); ?>/img/placeholder.png" alt="<?php the_title(); ?>" />
    					<?php endif; ?>
    					<?php if ( has_post_format('video') ) echo'<span class="thumb-icon"><i class="icon-play"></i></span>'; ?>
    					<?php if ( has_post_format('audio') ) echo'<span class="thumb-icon"><i class="icon-volume-up"></i></span>'; ?>
    				</a>
    				<?php if ( !wpb_option('post-hide-comments') ): ?><a class="entry-comments" href="<?php comments_link(); ?>"><i class="icon-comments-alt"></i><?php comments_number( '0', '1', '%' ); ?></a><?php endif; ?>
    			</div><!--/.entry-thumbnail-->
    
    			<ul class="entry-meta">
    				<?php if ( !wpb_option('post-hide-categories') ): ?><li class="category">In <?php the_category(' &middot; '); ?></li><?php endif; ?>
    				<?php if ( !wpb_option('post-hide-date') ): ?><li class="date"> &mdash; <?php the_time('j M, Y'); ?> <?php if ( !wpb_option('post-hide-detailed-date') ): ?><?php _e('at','typegrid'); ?> <?php the_time('g:i a'); ?><?php endif; ?></li><?php endif; ?>
    			</ul><!--/.entry-meta-->
    
    			<div class="clear"></div>
    
    			<h2 class="entry-title">
    				<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a>
    			</h2><!--/.entry-title-->
    
    			<div class="text">
    				<div class="excerpt">
    					<?php the_excerpt(); ?>
    					<?php if ( wpb_option('excerpt-more-link-enable') ): ?>
    						<div class="more-link-wrap">
    							<a class="more-link" href="<?php the_permalink(); ?>">
    								<i class="icon-share-alt"></i><span><?php echo wpb_option('read-more', __('(more...)','typegrid')); ?></span>
    							</a>
    						</div>
    					<?php endif; ?>
    				</div><!--/.excerpt-->
    			</div><!--/.text-->
    
    		</div><!--/.entry-inner-->
    	</article><!--/.entry-->	
    
    	<?php if($i % 2 == 0) { echo '</li><li class="entry-row">'; }	$i++; endwhile;	echo '</li>'; ?>
    
    </ul><!--/.entry-list-->
    
    <?php get_template_part('partials/pagination'); ?></blockquote>
  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    remove one category to display on home page

    consider to use 'pre_get_posts'

    http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
    http://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts#Exclude_categories_on_your_main_page

    alternatively, try to change this:

    query_posts( 'cat=-234' );

    to:

    global $query_string; query_posts( $query_string . '&cat=-234' );

    http://codex.wordpress.org/Function_Reference/query_posts#Preserving_Existing_Query_Parameters

  3. Suresh Patel
    Member
    Posted 1 year ago #

    Thanks alchymyth
    The tip you given is worked for me now it is working perfectly.

    Thanks again for the help.

    Regards,
    Suresh

Topic Closed

This topic has been closed to new replies.

About this Topic