简体   繁体   中英

How can I limit categories displaying in posts

I want to show the limited categories displaying in my post. Here is my blog page.

https://k2fly.com/blog/

Image

Kindly visit the page and give me advice how can i reduce category number displaying. I have tried with this codes but not working

<?php
// display 7 random categories

$cats ='';
$categories=get_categories('posts_per_page=5&exclude=' . $GLOBALS[asides_id]);
$rand_keys = array_rand($categories, 4);

foreach ($rand_keys as $key) {

    $cats .= $categories[$key]->term_id .',';

}

wp_list_categories('title_li=&include='.$cats);
?>

Would you please try the get_categories function in the following way?

$categories=get_categories( array(
'number' => 5,
'exclude' => $GLOBALS[asides_id]
) );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM