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://www.play.com/play/category/good/">good</a>
</li>
<li class="cat-item cat-item-6"><a href="http://www.play.com/play/category/collections/">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 />';
}
?>
What I did is use the 2nd option but I'm having problems displaying a specific category id. Code below display all categories though I only need to display categories under specific parent. which is cat id 2.
<?php
$categories = get_categories();
echo '<ul>';
foreach ($categories as $cat) {
if ($cat->category_parent != 0) {
echo '<li>';
}
echo '<a href="'.get_option('home').get_option('category_base').'/'.$cat->category_nicename.'/">'.$cat->cat_name.'</a>';
if ($cat->category_description != '') {
echo '<p>'.$cat->category_description.'</p>';
}
if ($cat->category_parent != 0) {
echo '</li>';
}
}
echo '</ul>';
?>
Corrected some looping and optimize abit
<?php
$categories = get_categories();
echo '<ul>';
foreach ($categories as $cat) {
if ($cat->category_parent != 0) {
echo '<li>';
echo '<a href="'.get_option('home').get_option('category_base').'/'.$cat->category_nicename.'/">'.$cat->cat_name.'</a>';
if ($cat->category_description != '') {
echo '<p>'.$cat->category_description.'</p>';
}
echo '</li>';
}
}
echo '</ul>';
?>