Results 1 to 7 of 7

Thread: i want show category name

  1. #1
    kevin is offline Hello World
    Join Date
    Jan 2010
    Posts
    8

    Default i want show category name

    hello
    this tage
    Code:
    <?php
    foreach((get_the_category()) as $category) { 
        echo $category->cat_name . ' '; 
    } 
    ?>
    show all category name (category and sub category name) in sub category page.


    i want showing only select category.

    example:
    -cat 14
    --cat 17
    --cat 18
    -cat 20
    --cat 22
    --cat 30

    in template sub cat id 17 show only sub cat17 name. dont show category14 name. or more category.

    thanks

  2. #2
    Jeffro's Avatar
    Jeffro is offline WPTavern Forum Admin
    Join Date
    Jan 2009
    Location
    Ohio
    Posts
    2,359

    Default

    I wonder if this function would be better to use in this case. Maybe not.

    http://codex.wordpress.org/Function_...tegory_by_slug

  3. #3
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,997

    Default

    Quote Originally Posted by kevin View Post
    hello
    this tage
    Code:
    <?php
    foreach((get_the_category()) as $category) { 
        echo $category->cat_name . ' '; 
    } 
    ?>
    show all category name (category and sub category name) in sub category page.


    i want showing only select category.

    example:
    -cat 14
    --cat 17
    --cat 18
    -cat 20
    --cat 22
    --cat 30

    in template sub cat id 17 show only sub cat17 name. dont show category14 name. or more category.

    thanks
    Where are you wanting to display this category list?
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  4. #4
    kevin is offline Hello World
    Join Date
    Jan 2010
    Posts
    8

    Default

    i want showing only select category name.

    -cat 14 name=a
    --cat 17 name=b
    --cat 18 name=c

    now x.com/?cat=18 show a c.
    i don't show a. i want show c.
    or
    x.com/?cat=17 show a b.
    i want showing b, in template.

  5. #5
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,997

    Default

    Quote Originally Posted by kevin View Post
    i want showing only select category name.

    -cat 14 name=a
    --cat 17 name=b
    --cat 18 name=c

    now x.com/?cat=18 show a c.
    i don't show a. i want show c.
    or
    x.com/?cat=17 show a b.
    i want showing b, in template.
    The easiest thing to do would be to make Cat 17 and Cat 18 parent categories (they are currently child categories of Cat 14).

    You can also try using the single_cat_title template tag.
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  6. #6
    chipbennett's Avatar
    chipbennett is offline WordPress Legend
    Join Date
    Feb 2009
    Location
    St. Louis, MO
    Posts
    1,997

    Default

    I just realized, your OP indicated that you were using get_the_category, which is intended only for use in the loop (unless you pass a PostID as a function parameter).

    Are you trying to display the category name inside the loop, or outside the loop?
    WP TurnKey - Turn-Key WordPress installation and maintenance services
    WordPress user since 2005 | @chip_bennett | chipbennett.net | cbnet Plugins

  7. #7
    kevin is offline Hello World
    Join Date
    Jan 2010
    Posts
    8

    Default

    oh thank you so much.
    this tage Show the First Category Name Only.

    <?php
    $category = get_the_category();
    echo $category[0]->cat_name;
    ?>
    ouside the loop.

    thanks much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •