• Hello,
    Am new to wordpress it’s really great.But, only problem am facing is that I want to show only subcategories names & links on the page of a parent category and don’t wanna show posts in the category having sub categories.
    for example :-

    a parent category is “songs”
    and subcategories in “songs” category are “pop-songs” & “movie-songs”
    so i wanna show only “pop songs” & “movie songs” names and links when i open link like this.

    https://www.example.com/songs

    and if “pop songs” have any subcategory it should show that sub category when i open link like this.

    https://www.example.com/songs/pop-songs

    I hope i explained what I wanna do.

    Thankyou very much ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • You want pretty links, refer to this article to set up your custom Permalink structure.

    You could make a Page called “Songs” and try this:

    <ul>
    <?php wp_list_categories('orderby=id&show_count=1
    &use_desc_for_title=0&child_of=8'); ?>
    </ul>

    Enter the parent-category ID where the ‘8’ is. Refer to this article for more details on “wp_list_categories”.

    And in general, get familiar with Template Tags. <– The key to WordPress. From this page you will find documentation on:

    • Stepping Into Template Tags (an introduction to Template Tags)
    • Anatomy of a Template Tag (details of how to put Tags into Template files)
    • How to Pass Tag Parameters (details of how to use Parameters with Tags)
    • Include Tags (additional tags not shown here, related to including one Template file within another)
    • Conditional Tags (more additional tags not shown here, related to making your Templates more flexible with options)
    • Templates (a comprehensive list of Template, Theme, and Tag resources)
    • Stepping Into Templates (introduction to Template files)

    Good luck, let me know how this goes I’ll keep watch on this post. Welcome to the WordPress community.

    Forgot, you wanted the same to work for subcategory pages. The code should be this:

    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>

    Hi, Where abouts do you put that code?

    Hi, Where abouts do you put that code?

    Code could go in the Page Template for that Page.

    Additional Resources:
    Stepping Into Templates
    Template Hierarchy

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show only sub-categories’ is closed to new replies.