0

How do I limit the number of tags shown using the code below, without having to add $count=0; or if ($count <= to the query, but only for the home page, and a different number for each set of post?

<?php the_tags('','','');?> 

I don't want to add the count option because my post loop is set up with that option and adding that to the tags query only throws my post off.

here is the query i use for my post.

<?php if (have_posts()) :
$count = 0;
while (have_posts()) : the_post();
    $count++;
    if ($count  == 1) : ?> <!--first box -->
        <div class="style-1"><?php the_content(); ?>
    <?php elseif ($count  > 1 && $count  <5) : ?></div> <!--next three boxes -->
        <div class="style-2"><?php the_content(); ?></div>
    <?php elseif ($count  == 5) : ?> <!-- box five and break div -->
        <div class="style-2"><?php the_content(); ?></div>
        <div class="first-break-div"><?php /* the content from first break div */ ?>    </div>
    <?php elseif ($count >5 && $count < 11) : ?> <!--next five boxes -->
        <div class="style-3"><?php the_content(); ?></div>
    <?php elseif ($count == 12) : ?> <!--last box and last break div -->
        <div class="style-3"><?php the_content(); ?></div>
        <div class="last-break-div"><?php /* the content from last break div */ ?>    </div>
    <?php endif;
 endwhile;
endif; ?>`
2
  • I don't understand your issue, you are showing 12 posts on your homepage. Where exactly are the_tags() coming in as this displays the tags attached to a post. your code and what you ask does not make sense Commented Sep 3, 2015 at 17:05
  • getversed.us @PieterGoosen Look at those four square post at the top
    – user32447
    Commented Sep 3, 2015 at 17:45

1 Answer 1

1

$count is just an arbitrary variable name. If you're using a separate loop to get tags and stop after a certain number (as shown on https://codex.wordpress.org/Function_Reference/get_the_tags), replace the $count variable in that example code with something like $tag_count or $counting or $treebark, and it won't mess up your use of $count in the posts Loop anymore.

2
  • Thanks @JayNeely that worked But one last thing. How can I make it link because right now it's not linking.
    – user32447
    Commented Sep 4, 2015 at 2:51
  • If you could, please update your code in the original question so we can see what you're currently doing.
    – Jay Neely
    Commented Sep 4, 2015 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.