0

Does anyone have any idea on how i can limit the number of tags shown in a post and if there is more it's a drop down menu.

Here's an example of what i mean.

enter image description here

Se where it sats "More On" those are the tags, I want to be able to show only 3 tags and then after that a drop down menu for the rest of the tags.

Is this possible, If so how can I do this. Only Tags Attached To The Post

0

This can be a start...

<?php
$tags = wp_get_post_tags($post_id);
$html = '<div class="post_tags">';
$i=1;
foreach ( $tags as $tag ) {
    $tag_link = get_tag_link( $tag->term_id );  
    if($i>3)
    {
        if($i==4)
        {
            $html .= '<ul class="post_tags_menu">';
        }
        $html .= "<li><a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
        $html .= "{$tag->name}</a><li>";
    }
    else
    {
        $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
        $html .= "{$tag->name}</a>";
    }
    $i++;
}
if($i>4)
{
    $html .= "</ul>";
}
$html .= '</div>';
echo $html;
?>

How to get post tags http://codex.wordpress.org/Function_Reference/wp_get_post_tags

| improve this answer | |
  • Only Tags Attached to the post not all tags – Mihad Aiko Feb 25 '13 at 7:47
  • @MihadAiko have edited my answer, please look.. – Rajeev Vyas Feb 25 '13 at 7:53
  • I don't even know where to begin with that :( @Rajeev – Mihad Aiko Feb 25 '13 at 8:00
  • Does Anyone else have an answer – Mihad Aiko Feb 25 '13 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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