Site icon Hip-Hop Website Design and Development

Record of subcategories with featured picture

In a web page, I have to show an inventory of all sub classes of a specify class.

For instance, within the class Sport have 6 subcategories:

  • Swim
  • Soccer
  • Basket
  • Ski
  • Hockey

Every subcategory has a featured picture, title and outline, which I might prefer to show.

I’ve add featured picture utilizing this code (in features.php):

add_action('init', 'my_category_module');
perform my_category_module() {
 add_action ( 'edit_category_form_fields', 'add_image_cat');
 add_action ( 'edited_category', 'save_image');
 }

perform add_image_cat($tag){
 $category_images = get_option( 'category_images' );
 $category_image = '';
 if ( is_array( $category_images ) && array_key_exists( $tag->term_id, $category_images ) ) {
 $category_image = $category_images[$tag->term_id] ;
 }
 ?>
 <tr>
 <th scope="row" valign="prime"><label for="auteur_revue_image">Picture</label></th>
 <td>
 <?php
 if ($category_image !=""){
 ?>
 <img src="<?php echo $category_image;?>" alt="" title=""/>
 <?php
 }
 ?>
 <br/>
 <enter kind="textual content" title="category_image" id="category_image" worth="<?php echo $category_image; ?>"/><br />
 <span>This discipline lets you add an image for example the class. Add the picture from the media tab WordPress and paste its URL right here.</span>
 </td>
 </tr>
 <?php
 }
perform save_image($term_id){
 if ( isset( $_POST['category_image'] ) ) {
 //load present class featured possibility
 $category_images = get_option( 'category_images' );
 //set featured put up ID to correct class ID in choices array
 $category_images[$term_id] =  $_POST['category_image'];
 //save the choice array
 update_option( 'category_images', $category_images );
 }
 }

class.php

<?php
 if(is_category()){
 $category_images = get_option( 'category_images' );
 $category_image = '';
 if ( is_array( $category_images ) && array_key_exists( get_query_var('cat'), $category_images ) ){

$category_image = $category_images[get_query_var('cat')] ;
 ?>
 <img src="<?php echo $category_image;?>"/>
 <?php
 }
 }
 ?>

I have to have a grid appear like this (that is for current put up )

With this I can show all classes with their descriptions, however how can I add the featured picture and show solely subcategories of sure class mum or dad?

<?php
$classes = get_categories( array(
    'orderby' => 'title',
    'order'   => 'ASC'
) );

foreach( $classes as $class ) {
    $category_link = sprintf( 
        '<a href="%1$s" alt="%2$s">%3$s</a>',
        esc_url( get_category_link( $category->term_id ) ),
        esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->title ) ),
        esc_html( $category->title )
    );

    echo '<p>' . sprintf( esc_html__( 'Class: %s', 'textdomain' ), $category_link ) . '</p> ';
    echo '<p>' . sprintf( esc_html__( 'Description: %s', 'textdomain' ), $category->description ) . '</p>';}

Additionally is feasible to show as a grid?

Thanks