Support » Plugins » Hacks » Sidebar tag check sees only tags from first 9 posts

  • Resolved edow



    I use the following code in my category sidebar to check which tags are used in the category. It works, but only for the first 9 posts (the first page displays 9 posts.) How can I change this code so it also checks for the other posts in this category?

    		if (is_category()){
    		  $cat = get_query_var('cat');
    		  $yourcat = get_category ($cat);
    		$tag_IDs = array();
    		if (have_posts()) : while (have_posts()) : the_post();
    		  $posttags = get_the_tags();
    		  if ($posttags):
    			foreach($posttags as $tag) {
    			if (!in_array($tag->term_id , $tag_IDs)):
    			   $tag_IDs[] = $tag->term_id; 
    			   $tag_names[$tag->term_id] = $tag->name;
    			   $tag_slug[$tag->term_id] = $tag->slug;
    		endwhile; endif;
    		$getTag = $_GET["tag"];
    		if ($getTag == '') { 
    			$tag_showall = 'checked';
    		if (!empty($tag_IDs)){
    			echo '<h3>Aanbieders</h3>';
    			echo '<input type="radio" name="tag" value="" '.$tag_showall.'> Alles weergeven<br>';
    		foreach($tag_IDs as $tag_ID){
    			$checked = $tag_slug[$tag_ID];
    			echo '<input type="radio" name="tag" value="'.$checked.'"' ;
    			if((isset($_GET["tag"])) && $_GET["tag"] == $checked) {
    			echo ' checked="checked"';
    			echo '> '.$tag_names[$tag_ID].'<br>';
Viewing 2 replies - 1 through 2 (of 2 total)
  • When I change this:

    to this:

    and I go to page 2 then it shows the tags from the post from page 2 (which it didn’t before) so that is a beginning.

    But then it leaves me with the following problems:

    1. It still doesn’t show all the tags from the whole category, but only from the current page
    2. When I’m on page 2 and click on a results it redirects to page 1 (that’s what I want), but then it doesn’t show the tag in the sidebar, because it’s not page 2 anymore

    I think I got it. I changed the line to:

    and now it works. I tried posts_per_page=-1 before without luck, but it seems that it works in combination with &paged='.$paged.'.

    Maybe someone can verify that this code is safe to use. Or maybe someone have a better solution.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sidebar tag check sees only tags from first 9 posts’ is closed to new replies.