WordPress.org

Ready to get started?Download WordPress

Forums

Make categories for post_type (10 posts)

  1. seravifer
    Member
    Posted 1 year ago #

    I have this code:

    <br />
    foreach((get_the_category()) as $category) {<br />
    echo '<li class="cat-' .$category->cat_name. '"><a>term_id ).'">' . $category->cat_name . '</a>';}<br />

    And I need it to work for post type "articles".

    Code: http://pastie.org/5125396

  2. alieneila
    Member
    Posted 1 year ago #

    if your custom post type uses the built in categories the above should work. If it has it's own custom taxonomy instead, you should use something like wp_get_object_terms instead
    http://codex.wordpress.org/Function_Reference/wp_get_object_terms

  3. seravifer
    Member
    Posted 1 year ago #

    Yes, I use a special taxonomy but not show it. This is called "categorias".

  4. seravifer
    Member
    Posted 1 year ago #

    How do I make it work?

  5. alieneila
    Member
    Posted 1 year ago #

    Are you trying to display a list of assigned categories at the bottom of a post, or?

  6. seravifer
    Member
    Posted 1 year ago #

    I need to show the categories to which my post_type "articulos".

  7. alieneila
    Member
    Posted 1 year ago #

    yes but where do you need to show them? On a sidebar to where all those post_type is articulos, or at the bottom of a post listing all of them that the post is assigned to? I will provide the function for you to do that, but both are different.

  8. seravifer
    Member
    Posted 1 year ago #

    OK, in line 26:
    http://pastie.org/5124323

  9. alieneila
    Member
    Posted 1 year ago #

    Ok, replace lines 26 and 27 with...

    <?php
    echo get_the_term_list( $post->ID, 'categorias', '<p>', ', ', '</p>' );
    ?>

    This will display links for each term with a comma separator.
    You can replace the <p> and </p> with whatever wrapper you want to use that wraps the entire list.

    If you want an actual list you can do...

    <?php
    echo get_the_term_list( $post->ID, 'categorias', '<ul id="my_term_list"><li class="categoria">', '</li><li>', '</li></ul>' );
    ?>
  10. seravifer
    Member
    Posted 1 year ago #

    Thanks, it works great

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.