limit get_categories() to only three categories
-
Hallo everyone,
I’m working on a website to wich I want to display three of the categories on the frontpage.
This is the code I’m using:
<?php $categories = get_categories( array( 'orderby' => 'name', 'hide_empty' => false, 'parent' => 0 ) ); ?> <?php foreach ( $categories as $category ) : ?> <div class="grid-3"> <div class="intro_linkToCategory"> <a href="<?php echo esc_url( get_category_link( $category -> term_id ) ); ?>"> <img src="<?php echo z_taxonomy_image_url( $category -> term_id ); ?>" /> <h2><?php echo $category->name; ?></h2> </a> </div><!-- end of intro_linkToCategory --> </div><!-- end of grid --> <?php endforeach; ?>
This code, however, displays all the avaliable categories. I want to limit
get_categories()
to show a limited amount of categories by category ID. I might have searched on the wrong places but I couldn’t find a solution to do this. I don’t want to show the posts of a category but just list the category name and image (using a plugin for the image) and link it to the correct category page.I’d like a point into the right direction or an example of working code that will point me on the right direction. I have a deadline of April 1st ( not a joke ) on this one and I’m starting to get nervous…
Thanks in advance,
Kind regards.
- The topic ‘limit get_categories() to only three categories’ is closed to new replies.