WordPress.org

Ready to get started?Download WordPress

Forums

Show only sub-categories (5 posts)

  1. omasti
    Member
    Posted 5 years ago #

    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.

    http://www.example.com/songs

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

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

    I hope i explained what I wanna do.

    Thankyou very much :-)

  2. iPaulPro
    Member
    Posted 5 years ago #

    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.

  3. iPaulPro
    Member
    Posted 5 years ago #

    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 } ?>
  4. jicola.com
    Member
    Posted 5 years ago #

    Hi, Where abouts do you put that code?

  5. MichaelH
    Member
    Posted 5 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic