• Resolved TiagoPires

    (@tiasch)


    If we’re in the ‘Movies’ archive page and we need to list ‘Directors’ on the sidebar. So Clicking on a director will take us to the archive of’Movies’ filtered by a direcotr like ‘Almodovar’ or ‘Woody Alen’.

    It’s a similar functionality to wp_list_categories() excepr that this cannot distinguish post types.

    Anyone has achieved this?

    http://wordpress.org/extend/plugins/cpt-onomies/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Well, considering the archive page you’re wanting is custom made, you’re going to have to print the directors list yourself and add in the link to your custom archive page.

    First, you need to decide what you want the URL to be for the movies archive page filtered by director. But, for this example, let’s say your movies archive page is http://mywebsite.com/movies/ and you want your movies-director archive page to be http://mywebsite.com/movies/director/woody-allen. Here’s what you do:

    Using the code on Custom CPT-onomy Archive Pages, add a rewrite rule to create your custom archive page. This will probably go in your functions.php file.

    add_action( 'init', 'my_website_add_rewrite_rule' );
    function my_website_add_rewrite_rule() {
    
       // allows our query to pick up the director slug
       add_rewrite_rule( '^movies/director/([^/]*)/?', 'index.php?post_type=movies&directors=$matches[1]&cpt_onomy_archive=1', 'top' );
    
    }

    Now all you need to do is print the list.

    // first, retrieve the directors terms
    if ( ( $directors = get_terms( 'directors' ) ) && !is_wp_error( $directors ) ) {
       ?><ul><?php
       // print each director with your custom link
       foreach ( $directors as $director ) {
             ?><li><a href="<?php echo get_post_type_archive_link( $post_type ); ?>director/<?php echo $director->slug; ?>"><?php echo $director->name; ?></a></li><?php
          }
       ?></ul><?php
    }

    Was that helpful?

    Thread Starter TiagoPires

    (@tiasch)

    Spot on! I’m proud that I got close, with a lot more code, but close. Your code is so much better! 😛 Thanks for all your help Rachel! unreal!

    Good deal! Glad I could help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Sidebar List with terms linking to archive page’ is closed to new replies.