Jump to content
Sign in to follow this  
thelbc

Exclude Sticky post from the loop - Pagination Bug

Recommended Posts

thelbc    0
thelbc

Hi there, I used the following code to remove the sticky posts from the loop used on the index page of my site :

	add_action('pagelines_before_theloop', 'exclude_cat');
	
	function exclude_cat(){
			if (is_home()) {
	query_posts(array("post__not_in" =>get_option("sticky_posts")));
		}
	}
	
The problem is that now my pagination is not working anymore... So I tried using this
	add_action('pagelines_before_theloop', 'exclude_cat');
	
	function exclude_cat(){
		if (is_home()) {
	$page = (get_query_var('paged')) ? get_query_var('paged') : 1;
	$args = array(
	'paged' => $page,
	'post__not_in' => get_option("sticky_posts")
	);
	query_posts($args);
	    }
	}
	

And then, the problem is that my fullwidth posts (using Magazine Layout Mode Only) are not displayed anymore... Any advices would be much appreciated. Cheers, Jk_

Share this post


Link to post
Share on other sites
cmunns    16
cmunns

Why couldn't you just use this? function exclude_cat(){ if (is_home()) { query_posts(array("post__not_in" =>get_option("sticky_posts"))); } }

Share this post


Link to post
Share on other sites
Andrew    201
Andrew

Let's start with the objective. You don't want 'sticky' posts to appear on your posts page?

Share this post


Link to post
Share on other sites
thelbc    0
thelbc

@cmunns : I did at first but then I realized that the pagination is not working anymore! @arpowers : The objective is that I don't want sticky post on the mainpage (however I only request them from an other query on top of the page).

Share this post


Link to post
Share on other sites
cmunns    16
cmunns

you request them with another query? What's the point? I still think you could just use css if you're only trying to hide them on the home page. Can you be even more specific about the goal?

Share this post


Link to post
Share on other sites
thelbc    0
thelbc

Sorry that I have been unclear on my purpose! Here is what I have done... Display a homemade news slider and display it at the top of my homepage:

<?php
	
	$args=array(
	'post__in' =>get_option("sticky_posts"),
	'showposts'=>12,
	);
	$my_query = get_posts($args);
	$chunked_posts = array_chunk($my_query,1);
	?>
	<?php foreach($chunked_posts as $recent): ?>
	    <div>
	        <?php foreach($recent as $post): setup_postdata($post);?>
	            <div class="thumb-container">
					<?php if ( has_post_thumbnail()) the_post_thumbnail('feature-image'); ?>
					<div class="overlay-text">
					/<?php echo $post->post_name; ?>" title="<?php echo $post->post_slug; ?>">
						<span class="thumb-size">
						<p class="text-overlay"><?php echo $post->post_title; ?></p>
						</span>
					
					</div>
				</div>
	         <?php endforeach;?>
	    </div>
	<?php endforeach;?>[/code]

	
	[b]Then exclude sticky post from my main query :[/b]
	
	
[code]add_action('pagelines_before_theloop', 'exclude_cat'); function exclude_cat(){ if (is_home()) { $page = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'paged' => $page, 'post__not_in' => get_option("sticky_posts") ); query_posts($args); } }

And now it works like it should. Thanks, Jk_

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×