I'm building a WooCommerce shop that shows 6 categories, handpicked by the shopowner, on the homepage.
I want to be able to manage the 6 categories in WordPress, so we can change things up every once in a while.
In the current situation, we're excluding one categorie ID (51) with an if-statement.
Here's the code:
$taxonomy = 'product_cat';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
$empty = 0;
$args = array(
'taxonomy' => $taxonomy,
'orderby' => $orderby,
'show_count' => $show_count,
'pad_counts' => $pad_counts,
'hierarchical' => $hierarchical,
'title_li' => $title,
'hide_empty' => $empty
);
$all_categories = get_categories( $args );
echo '<ul class="small-block-grid-1 medium-block-grid-3">';
foreach ($all_categories as $cat) {
if ($cat->category_parent == 0 && $cat->term_id != 51) {
$category_id = $cat->term_id;
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
echo '<li class="single-news-post"><a href="'. get_term_link($cat->slug, 'product_cat').'">';
$image = wp_get_attachment_url( $thumbnail_id );
if ($image) {
echo '<img src="' . $image . '" alt="' . $cat->name . '" />';
}
echo '<h3>'. $cat->name .'</h3>';
echo '</a></li>';
}
}
Is it possible to handpick the categories we want to show and manage these categories through our dashboard?
Thanks!