Forums

Show only a parent category (6 posts)

  1. Pedro
    Member
    Posted 2 years ago #

    Hi guys!!

    I would like to change the code of how categories are showed. I use two parents categories: Location and topic.

    I would like to change this php code:
    <span class="cat-links"><?php printf(__('Posted in %s', 'sandbox'), get_the_category_list(', ') ) ?></span>

    bu other that shows only Location parent category, just putting "Location: ..." and it should show the subcategory of location I chose.

    I hope someine understand it.

    http://www.igmosi.com/blog

    thanks!!!

  2. ericdaams
    Member
    Posted 2 years ago #

    I think I basically understand what you're trying to do, though it looks like you've already figured this out? For example, on the post I looked at it had this:

    Location: Finland ยป Helsinki

    Let me know if you were trying to do something different.

  3. Pedro
    Member
    Posted 2 years ago #

    Hi thanks!!

    no, that is written in body of the post. I would like to do it where categories are showed (right of the picture), like:
    Location: (should be showed the cateogires I choose, that case Finland)
    Topic: (should be showed the cateogires I choose, that case Street art)

    I would like to modify the code to show those 2 different group of categories. My categories are divided in 2 (topic and location) parents field. I have gone through that and I guess I have to change the function get_the_category_list(', ') , but i havent figured it out.

    got it?

    thanks!!!

  4. MichaelH
    Volunteer
    Posted 2 years ago #

    Not a good idea to change 'core code' ... probably should use Template_Tags/get_the_category then display those as you see fit.

  5. Pedro
    Member
    Posted 2 years ago #

    Ok, I got it,

    but how I select the parent "LOCATION" in this sentences;

    <?php the_category( $separator, $parents, $post_id ); ?>

    should be:

    <?php the_category( ' , ', 'Location'); ?>

    it didnt work.

  6. ericdaams
    Member
    Posted 2 years ago #

    You need to use the id of the Location category, not the name. So if the ID of the Location category is 2, you'd have something like:

    <?php $location = get_the_category(' ,', '2', $post->ID);
    echo $location; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic