admin管理员组文章数量:1425739
I use this code to display some of the categories:
<?php
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC',
'exclude' => 'all',
'include' => '135,19,124,133,126',
) );
foreach ($categories as $category) {
echo '<div class="category-list">';
echo '<a href="' . get_category_link( $category->term_id ) . ' "><div class="image_wrapper2 is-image list-image">'. do_shortcode(sprintf('[wp_custom_image_category term_id="%s"]',$category->term_id)). '</div></a>' ;
echo '<div class="image-category-mosje"><h2 class="title-category"><a href=" ' . get_category_link( $category->term_id ) . ' "> '.$category->name.' </a></h2></div>';
echo '<span class="category-count"> ' . $category->count . '</span>';
echo '</div>';
}
?>
But there is a problem displaying in alphabetical order. I want the show to be random and every time it has a different order. Can anyone help?
I use this code to display some of the categories:
<?php
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC',
'exclude' => 'all',
'include' => '135,19,124,133,126',
) );
foreach ($categories as $category) {
echo '<div class="category-list">';
echo '<a href="' . get_category_link( $category->term_id ) . ' "><div class="image_wrapper2 is-image list-image">'. do_shortcode(sprintf('[wp_custom_image_category term_id="%s"]',$category->term_id)). '</div></a>' ;
echo '<div class="image-category-mosje"><h2 class="title-category"><a href=" ' . get_category_link( $category->term_id ) . ' "> '.$category->name.' </a></h2></div>';
echo '<span class="category-count"> ' . $category->count . '</span>';
echo '</div>';
}
?>
But there is a problem displaying in alphabetical order. I want the show to be random and every time it has a different order. Can anyone help?
Share Improve this question edited Jun 25, 2019 at 7:59 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Jun 25, 2019 at 7:35 omid chahardoliomid chahardoli 191 silver badge9 bronze badges1 Answer
Reset to default 0get_categories
doesn't allow you to set rand
as orderby
AFAIR, but that's not a big deal. It returns an array, so in your case all you have to do is to shuffle that array:
<?php
$categories = get_categories( array(
'orderby' => 'name',
'order' => 'ASC',
'exclude' => 'all',
'include' => '135,19,124,133,126',
) );
shuffle ( $categories );
foreach ($categories as $category) {
echo '<div class="category-list">';
echo '<a href="' . get_category_link( $category->term_id ) . ' "><div class="image_wrapper2 is-image list-image">'. do_shortcode(sprintf('[wp_custom_image_category term_id="%s"]',$category->term_id)). '</div></a>' ;
echo '<div class="image-category-mosje"><h2 class="title-category"><a href=" ' . get_category_link( $category->term_id ) . ' "> '.$category->name.' </a></h2></div>';
echo '<span class="category-count"> ' . $category->count . '</span>';
echo '</div>';
}
?>
本文标签: Display some WordPress categories as random order
版权声明:本文标题:Display some WordPress categories as random order 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745372477a2655790.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论