I have created the 2 categories. And these two categories have child category, how can i get the post of the category when I clicked on the category title. Please guide me

  • just simple call category in menu, when u click category post automatic call in loop Apr 4, 2013 at 4:53

1 Answer 1

    // Get the ID of a given category
    $category_id = get_cat_ID( 'Category Name' );

    // Get the URL of this category
    $category_link = get_category_link( $category_id );

<!-- Print a link to this category -->
<a href="<?php echo esc_url( $category_link ); ?>" title="Category Name">Category Name</a>

After you click on the Category Title link, it will take you to the page where it displays all the posts under that category. Note: category.php, archive.php template files are responsible for the display, else index.php will be used.

  • I have included category.php, archive.php. It takes category.php but loop is not working, can u help me in that
    – sindhu
    Apr 4, 2013 at 5:48
  • I have created post in custom post type. Please guide me
    – sindhu
    Apr 4, 2013 at 5:54
  • If you are using custom post type, have you attached the category to it ? or any custom taxonomy/term ? Go through the template hierarachy here and you can modify the template loop. codex.wordpress.org/images/1/18/Template_Hierarchy.png Can you paste the code ? Apr 4, 2013 at 6:48
  • I created custom taxonomy, used as $args = array('taxonomy' => 'product-categories', 'walker' => null, 'title_li' =>'', 'type' =>'products'); ?> <ul> <?php wp_list_categories($args); ?></ul>
    – sindhu
    Apr 4, 2013 at 6:50
  • I solved the issue, I created taxonomy-product-categories.php. Now the loop working fine
    – sindhu
    Apr 4, 2013 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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