Jump to content


Photo

Exclude Sticky post from the loop - Pagination Bug


This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1 thelbc

thelbc

    Member

  • Members
  • PipPip
  • 13 posts

Posted 25 October 2010 - 10:03 AM

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_

#2 cmunns

cmunns

    Advocate

  • Members

  • 6537 posts

Posted 25 October 2010 - 04:49 PM

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

#3 arpowers

arpowers

    Founder

  • Administrators
  • 3253 posts

Posted 25 October 2010 - 04:49 PM

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

#4 thelbc

thelbc

    Member

  • Members
  • PipPip
  • 13 posts

Posted 26 October 2010 - 12:13 PM

@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).

#5 cmunns

cmunns

    Advocate

  • Members

  • 6537 posts

Posted 26 October 2010 - 05:11 PM

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?

#6 thelbc

thelbc

    Member

  • Members
  • PipPip
  • 13 posts

Posted 27 October 2010 - 08:27 AM

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">
					<a>/<?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>
					</a>
					</div>
				</div>
	         <?php endforeach;?>
	    </div>
	<?php endforeach;?>

Then exclude sticky post from my main query :

 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_