Group categories by genre

Discussion in 'WordPress' started by Ruriko, Apr 10, 2014.

  1. #1
    I'm trying to make an anime streaming site and I want to group categories by genre. Lets say the category can belong to several genres e.g actions,horror,mystery and another category belong to actions,horror,romance. How do I group categories into genres? Cause in the most basic structure, we group posts into category. Now i want group categories into genres

    Then be able to display the category in the genre by a url such as http://www.domain.com/genre/actions and it will list all categories in it. Here's an example site that has this feature http://www.animetv.org/genres/shoujo/
     
    Ruriko, Apr 10, 2014 IP
  2. themes4all

    themes4all Well-Known Member

    Messages:
    662
    Likes Received:
    47
    Best Answers:
    6
    Trophy Points:
    100
    #2
    hello there,

    in your case you have to play with taxonomy.. the first thing to do is to register the taxonomy : genre
    Here is a more info about this : Link

    Next, go to Settings => Permalinks.
    Set your permalinks to be /genre/%genre%/%category%/%postname%'/ and your category base to be /genre/all/

    Now add this Function :

    
    function Blueseodesign_post_type_link( $permalink, $post ) {
        if ( 'post' == $post->post_type ) {
            $genre = 'all';
            if ( false !== strpos( $permalink, '%genre%' ) ) {
                $first_genre = wp_get_object_terms( array( $post->ID ), 'genre', array( 'orderby' => 'term_id', 'count' => 1 ) );
                if ( ! is_wp_error( $first_genre ) && !empty( $first_genre ) ) {
                    $first_genre = array_shift( $first_genre );
                    $genre = $first_genre->slug;
                }
            }
            return str_replace( '%genre%', $genre, $permalink );
        }
    
        return $permalink;
    }
    add_filter( 'post_link', 'Blueseodesign_post_type_link', 10, 2 );
    
    Code (markup):
    You will end up with this links :

    /genre/genre-name/
    /genre/genre-name/category/
    /genre/genre-name/category/post-name

    But if you would like to list a Categories by Genre, you can use this Function : https://gist.github.com/mboynes/5732600

    Goodluck
     
    themes4all, Apr 11, 2014 IP