• Hi, I am new to wordpress. I’ve been searching for a solution to my problem. I found this code that solved my problem, but unfortunately I can’t style the sub categories differently from the parent category. I need to put an image in the parent category and under the parent a list of sub category links. Im not a php coder, can anyone show me how?

    <?php get_header(); ?>
    <div id="content">
    <?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb('<p   id="breadcrumbs">','</p>');} ?>
        <div id="cont_left">
        <h1><?php single_cat_title( '', true ); ?></h1>
        <?php
            if (is_category()) {
                $this_category = get_category($cat);
                if (get_category_children($this_category->cat_ID) != "") {
                 echo '<div id="cat-display"><ul>';
                    $childcategories = get_categories(array(
                      'orderyby' => 'name',
                       'hide_empty' => false,
                       'child_of' => $this_category->cat_ID
                       ));
    
                 foreach($childcategories as $category) {
                      echo '<img src="http://marinelcdpro.com/wp-  content/uploads/2014/05/' . $category->cat_ID . '.jpg" alt="' . $category->cat_name . '"  />';
                      echo '<a href="' . get_category_link( $category->term_id  ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' .  $category->      name.'</a>';
    
                        echo '<p>'.$category->description.'</p>';
                 }
                 echo '</ul></div>';
             }
            }
            ?>
        </div>
        <div ><?php get_sidebar(); ?></div>
    <div class="clear"></div>
    </div>
    <?php get_footer(); ?>

    I want something like this

    <ul>
     <h2>Category 1</h2>
     <p>Description of the Category1</p>
     <li>Sub Category link 1</li>
     <li>Sub Category link 2</li>
     <li>Sub Category link 3</li>
    </ul>
    
    <ul>
     <h2>Category 2</h2>
     <p>Description of the Category2</p>
     <li>Sub Category link 1</li>
     <li>Sub Category link 2</li>
     <li>Sub Category link 3</li>
    </ul>
    
     <ul>
     <h2>Category 3</h2>
     <p>Description of the Category3</p>
     <li>Sub Category link 1</li>
     <li>Sub Category link 2</li>
     <li>Sub Category link 3</li>
    </ul>
  • The topic ‘Style sub categories differently from its parent category’ is closed to new replies.