Before you ask please READ THIS

show filter in "multiple work lists based"

edited April 2013 in Beach Please Posts: 5
Ok. My question is a little bit complex.

I made some changes on file "cpt_work.php" from this:

register_taxonomy("genre", array(CUSTOM_POST_TYPE_WORK),
            array(
                "hierarchical" => false,
                "label" => __be('Categorias de Entidade'),
                "labels" => $genre_labels,
                "rewrite" => true,
                'show_admin_column' => true
            )
        );
to this:

register_taxonomy("genre", array(CUSTOM_POST_TYPE_WORK),
            array(
                "hierarchical" => true,     //this is the changed line from false to true
                "label" => __be('Categorias de Entidade'),
                "labels" => $genre_labels,
                "rewrite" => true,
                'show_admin_column' => true
            )
        );
As you know, this little change made my taxonomy "My works" work as wordpress category instead wordpress tags. On this way, now I can have subcategories inside main category (hierarchial) and call a specific category with all content of subcategories inside of it. I needed to change that cause my client have to insert data via wp-admin as categories and with specific post types that I have been created.
But..this small modification brings me other problem. Now, when I choose a specific category to show it on menu, the filter doesnt apear at all. It make sense cause if I only choose a "tag" I dont need to see filter. But I have hierarchical structure (categories) so I need to show filter anyway.

My question is how can I show the filter?
If you dont understand my question very good, I am sure if you check by yourself you can get my point. So I give you my URL: http://dev110.cartaodescontos.pt and if you want I will give you admin access to wp-admin to check the categories.

You may see one category here: http://dev110.cartaodescontos.pt/genre/pontos-de-distribuicao/
And another one here: http://dev110.cartaodescontos.pt/genre/aderentes/

Each of these have sub-categories, child-categories (or what you want to call them) inside... And I want to show filter to allow the user to choose what sub-categories he want to see inside...

Many thanks! Hope you can help me.


Post edited by Air on

Comments

  • AirAir
    Posts: 10,970
    Hi :-)

    Even with all that story I am still not convinced that you should use hierarchical here, but even more I am concerned how many issues you could face cause of that. Lets hope not many :-)

    But to the topic. In works-list.php you have two ifs with use $genre_template - they are there to hide filter when showing only one genre and to display only posts of current genre.

    You should check both "ifs" but to show filter remove second one. Change:
    
    if($genre_template !== true){
                //prepare filter
                $terms = get_terms('genre', 'hide_empty=1');
    
                if( count( $terms ) ):
                    echo '<ul id="genre-filter" >';
    
                    echo '<li class="label">'.__fe( 'Filter' ).'</li>';
                    echo '<li class="selected" data-filter="__all"><a href="' . a13_current_url() . '">' . __fe( 'All' ) . '</a></li>';
                    foreach($terms as $term) {
                        echo '<li data-filter="'.$term->slug.'"><a href="'.esc_url(get_term_link($term)).'">' . $term->name . '</a></li>';
                    }
    
                    echo '</ul>';
                endif;
            }
    
    to:
    
                //prepare filter
                $terms = get_terms('genre', 'hide_empty=1');
    
                if( count( $terms ) ):
                    echo '<ul id="genre-filter" >';
    
                    echo '<li class="label">'.__fe( 'Filter' ).'</li>';
                    echo '<li class="selected" data-filter="__all"><a href="' . a13_current_url() . '">' . __fe( 'All' ) . '</a></li>';
                    foreach($terms as $term) {
                        echo '<li data-filter="'.$term->slug.'"><a href="'.esc_url(get_term_link($term)).'">' . $term->name . '</a></li>';
                    }
    
                    echo '</ul>';
                endif;
    
    Hope that helps.

    With regards.
  • Ok, thanks!
    It works good.

    But the filter shows all categories in both pages. Im trying to show only sub-categories of category that is being played on page. I think the query must be the same and after, I have to filter the results by using current category. How can I do this?
  • AirAir
    Posts: 10,970
    Yes, you probably should. As I told you, your change might cause some problems.

    Unfortunately I don't have time to dig into hierarchical taxonomies, so you will have to do it alone.

    Anyway most if not all code you will be editing is in works-list.php. More info about taxonomies you can find in wordpress Codex
    http://codex.wordpress.org/Taxonomies
    http://codex.wordpress.org/Function_Reference/register_taxonomy

    If I will find anything about your case I will let you know here.

    With regards.
  • Ok. thanks!
    I am investigating by my self...and Im a little more close from solution
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!