Skip to content

Instantly share code, notes, and snippets.

@stephanieleary
Created October 16, 2016 20:13
Show Gist options
  • Save stephanieleary/189cf7939bc336590ecbd1aa40471302 to your computer and use it in GitHub Desktop.
Save stephanieleary/189cf7939bc336590ecbd1aa40471302 to your computer and use it in GitHub Desktop.
List post type links instead of posts if this taxonomy archive includes multiple post types
<?php
add_action( 'genesis_meta', 'scl_taxonomy_loop_switch' );
function scl_taxonomy_loop_switch() {
if ( function_exists( 'scl_find_post_type' ) )
$type = tees_find_post_type();
else
$type = get_query_var( 'post_type' );
if ( empty( $type ) || 'any' == $type || is_array( $type ) ) {
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'scl_list_taxonomy_post_types', 1 );
}
else
add_action( 'genesis_loop', 'tees_sticky_post_loop', 1 );
}
function scl_list_taxonomy_post_types() {
$current_term = get_queried_object();
$tax_obj = get_taxonomy( $current_term->taxonomy );
if ( count( $tax_obj->object_type ) ) {
echo '<div class="entry"><ul class="post-type-list">';
foreach ( $tax_obj->object_type as $post_type ) {
$label = get_post_type_object( $post_type )->labels->singular_name;
$link = add_query_arg( array( $current_term->taxonomy => $current_term->slug ), get_post_type_archive_link( $post_type ) );
echo '<li><a href="' . $link . '">' . $label . '</a></li>';
}
echo '</ul></div>';
}
}
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment