Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit number of items to display #9

Open
ericamigo opened this issue Jul 21, 2012 · 1 comment
Open

Limit number of items to display #9

ericamigo opened this issue Jul 21, 2012 · 1 comment

Comments

@ericamigo
Copy link

i want my site to display only about ten (10) taxonomy items in index page. can you please provide me a code for this? been looking a contact email of you for the past few days from now. hope you can help me with this.

@berteh
Copy link

berteh commented Apr 25, 2013

maybe adapting the following works for you:

$limit = 10;
$id = get_the_ID();
$post_type = get_post_type($id);
$taxonomies = get_object_taxonomies($post_type);
$out_images = $out_texts = array();

foreach ($taxonomies as $taxonomy) {
    if ($taxonomy == 'post_format') //internal WP3.1+ taxonomy, skip.
        continue;
    //next filter shows notice on blog if images not activated for taxonomy
    $terms = apply_filters( 'taxonomy-images-get-the-terms', '', array(
       'taxonomy'     => $taxonomy,
       'post_id' => $id,
       'having_images' => !$include_text_terms       
    ) );    
    $t = get_taxonomy($taxonomy);
    $label_array = array($t->label, $t->labels->singular_name, $taxonomy);
    $label = current(array_filter($label_array));               

    if ( !empty( $terms ) ) {   
        $count = $limit;        
        foreach ( $terms as $term ) {
            if (!empty($term->image_id))
                $out_images[] = '<li class="taxonomy-image taxo-'.$taxonomy.'"><a href="' . esc_url( get_term_link( $term, $taxonomy ) ) . '" title="'.$term->name.' ('.$label.')">' . wp_get_attachment_image( $term->image_id, 'detail' ) . '</a></li>';
            elseif ($include_text_terms) {                  
                $out_texts[] = '<a href="' .get_term_link($term->slug, $taxonomy) .'" title="'.$term->name.' ('.$label.')">'.$term->name.'</a>';            
            }
            if ($count-- == 0) continue; //limit reached.
        }
    }
}
if ($out_texts)
    $out_images[] = '<li class="taxonomy-text">'.join( ', ', $out_texts).'</li>';  

return '<ul class="taxonomy-images-the-terms">'.join( '', $out_images).'</ul>';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants