mardi 28 juin 2016

display categories with full details

I need to display the categories on my wordpress which has a parent and have sub categories under it. The main problem is that 'm having trouble displaying all the categories with full details with description and a unique div on it for an image.

The ones I'm using right now is this. Reference for the string args for this method is here

<ul>
    <?php wp_list_categories( array(
        'title_li' => __( 'asd' ),
            'hide_title_if_empty' => false,
        'show_option_all' => false,
            'use_desc_for_title' => true,
            'child_of' => 2
    ) ); ?>
</ul>

It generates everything I need except that I need to display the description as a text below the title and create a div to place an image on it.

<ul>
<li class="categories">asd
   <ul>
      <li class="cat-item cat-item-10"><a href="http://ift.tt/292iNEA">good</a>
      </li>
      <li class="cat-item cat-item-6"><a href="http://ift.tt/291C0tR">collections</a>
      </li>
   </ul>
</li>
</ul>

The second option that I have is this one. Basically its a custom way of generatng list of categories but not quite sure if I can able to only display the categories under the child of page id 2 which is the parent category. and also hide the element which is displaying how many post do I have on a category.

<?php
$categories = get_categories();
foreach ($categories as $cat) {
    if ($cat->category_parent != 0) {
        echo '<span style="padding-left:10px;">';
    }
    echo '<a href="'.get_option('home').get_option('category_base').'/'.$cat->category_nicename.'/">'.$cat->cat_name.'</a> ('.$cat->category_count.')';
    if ($cat->category_description != '') {
        echo ' - '.$cat->category_description;
    }
    if ($cat->category_parent != 0) {
        echo '</span>';
    }
    echo '<br />';
}
?>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire