WordPress.org

Ready to get started?Download WordPress

Forums

Display subcategory slug (2 posts)

  1. nathinah
    Member
    Posted 1 year ago #

    Hi!
    I'm building a portfolio site with many categories. One of them have subcategories.
    (Portfolio -> Packaging, Graphic, Handmade, ...)

    I need to display only the subcategory slug in my template. I used this code:

    <?php echo get_category(get_query_var('cat'))->slug; ?>

    but the result is "portfolio". How can I display only "handmade"?

    Thanks for any help :)

  2. nathinah
    Member
    Posted 1 year ago #

    I found the solution!

    <?php $args = array('parent' => 13);
    $categories = get_categories( $args );
    foreach($categories as $category) {
        echo $category->slug.' ';
    } ?>

Topic Closed

This topic has been closed to new replies.

About this Topic