Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to display this all categories and description in home page and for each category the division will be like this:

Category name Category Description Link to particular Categories post.

Help me that how to list out my categories name & in description how to add the tag in wordpress?

share|improve this question
1  
What have you tried so far, what code have you written so far, where are you going wrong, what error does your code give you. Please edit your question and add all relevant code, effort and research. As your question currently stands, it is a do-my-work-for-me type of question, which WPSE is not –  Pieter Goosen May 6 at 6:35

2 Answers 2

Use wp_list_categories

Here's all the parameters

<?php $args = array(
'show_option_all'    => '',
'orderby'            => 'name',
'order'              => 'ASC',
'style'              => 'list',
'show_count'         => 0,
'hide_empty'         => 1,
'use_desc_for_title' => 1,
'child_of'           => 0,
'feed'               => '',
'feed_type'          => '',
'feed_image'         => '',
'exclude'            => '',
'exclude_tree'       => '',
'include'            => '',
'hierarchical'       => 1,
'title_li'           => __( 'Categories' ),
'show_option_none'   => __( 'No categories' ),
'number'             => null,
'echo'               => 1,
'depth'              => 0,
'current_category'   => 0,
'pad_counts'         => 0,
'taxonomy'           => 'category',
'walker'             => null
); ?>
share|improve this answer
    
Thank you. but do you know about the how to add the html tag in category description field?? –  user51272 May 6 at 6:41
1  
What have you tried so far? –  Brad Dalton May 6 at 7:07

The easiest way to go about this is to first get all the categories using get_categories and then use WP_Query to create a query that will loop through the posts and return them according to the category to which they belong.

Here is the code I came up with. Proper explanation is included in the code

<?php
$categories = get_categories(); //retrieve all the categories and save them as a variable $categories

    foreach($categories as $category) : // Use foreach to split $categories into individual categories and store as variable $category
?>
    <p><?php // Display the category name as a link to the actual category ?>
        Category: <a href="<?php get_category_link( $category->term_id )?>" title="<?php sprintf( __( "View all posts in %s" ), $category->name ) ?>"><?php echo $category->name ?></a> 
    </p>

    <p><?php // Display the category description ?>
        Description: <?php echo $category->description ?>
    </p>

<?php
    $catid = $category->cat_ID; //Store the category ID as a variable to be used in WP_Query

    $args = array( 
        'cat' => $catid,
    );

    $query = new WP_Query($args);   

    // Start the Loop. You can use your own loop here
        while ( $query->have_posts() ) : $query->the_post(); 
    ?>  
        <p> 
            <?php the_title(); //Display only the title of the posts in the category ?> 
        </p>
    <?php
        endwhile;
    endforeach;
?>

You can use your own loop and html tags and place your divs where you want them to be displayed. You can use this code where you need to display your list.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.