Community Forums › Forums › Archived Forums › Design Tips and Tricks › Filterable custom post type isotope
Tagged: CPT, filterable grid, isotope, taxonomy archive
- This topic has 1 reply, 2 voices, and was last updated 7 years, 3 months ago by Brad Dalton.
-
AuthorPosts
-
July 11, 2017 at 10:31 am #208974MaffyParticipant
Hi, I need to create a custom post type (Resource) with a tassonomy Category Resource.
The archive page should view all custom posts with categories that can be filtered with isotopes. Similar of this http://tutorials.llamapress.com/portfolio/
I found this code explained in various tutorials but custom posts do not appear on the archive page. I do not understand what the problem is. Can you help me? Thank you!code on file function.php
/** Creates resources featured image for archive grid */ add_image_size( 'resources', 330, 230, TRUE ); /** Create resourse custom post type */ add_action( 'init', 'resources_post_type' ); function resources_post_type() { register_post_type( 'resources', array( 'labels' => array( 'name' => __( 'Resources' ), 'singular_name' => __( 'Resources' ), ), 'exclude_from_search' => true, 'has_archive' => true, 'hierarchical' => true, 'taxonomies' => array( 'resources-type' ), 'public' => true, 'rewrite' => array( 'slug' => 'resources' ), 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes', 'genesis-seo', 'genesis-cpt-archives-settings' ), ) ); } /* Register Resources Taxonomy */ add_action( 'init', 'create_resources_tax' ); function create_resources_tax() { register_taxonomy( 'resources-type', 'resources', array( 'label' => __( 'Resources Type' ), 'hierarchical' => true ) ); }
code on archive-resources.php
<?php /** * The custom resources post type archive template for a Filterable resources */ # Force full width content add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' ); wp_enqueue_script('isotope', get_stylesheet_directory_uri() . '/js/jquery.isotope.min.js', array('jquery'), '1.5.25', true); wp_enqueue_script('isotope_init', get_stylesheet_directory_uri() . '/js/isotope_init.js', array('isotope'), '', true); //* Add custom body class add_filter( 'body_class', 'filerable_resources_add_body_class' ); //* Filterable resources custom body class function filerable_resources_add_body_class( $classes ) { $classes[] = 'filterable-resources-page'; return $classes; } remove_action( 'genesis_loop', 'genesis_do_loop' ); add_action( 'genesis_loop', 'filterable_resources_do_loop' ); /** * Outputs a custom loop * * @global mixed $paged current page number if paginated * @return void */ function filterable_resources_do_loop() { ?> <header id="page-heading" class="entry-header"> <?php $terms = get_terms( 'resources-type' ); ?> <?php if( $terms[0] ) { ?> <ul id="resources-cats" class="filter clearfix"> <li><a href="#" class="active" data-filter="*"><span><?php _e('All', 'genesis'); ?></span></a></li> <?php foreach ($terms as $term ) : ?> <li><a href="#" data-filter=".<?php echo $term->slug; ?>"><span><?php echo $term->name; ?></span></a></li> <?php endforeach; ?> </ul><!-- /resources-cats --> <?php } ?> </header><!-- /page-heading --> <div class="entry-content" itemprop="text"> <?php if( have_posts() ) { ?> <div id="resources-wrap" class="clearfix filterable-resources"> <div class="resources-content"> <?php $wpex_count=0; ?> <?php while( have_posts() ) : the_post() ?> <?php $wpex_count++; ?> <?php $terms = get_the_terms( get_the_ID(), 'resources-type' ); ?> <?php if ( has_post_thumbnail($post->ID) ) { ?> <article class="resources-item col-<?php echo $wpex_count; ?> <?php if( $terms ) foreach ( $terms as $term ) { echo $term->slug .' '; }; ?>"> <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php echo genesis_get_image( array( size => 'resources' ) ); ?> <div class="resources-overlay"><h3><?php the_title(); ?></h3></div><!-- resources-overlay --></a> </article> <?php } ?> <?php endwhile; ?> </div><!-- /resources-content --> </div><!-- /resources-wrap --> <?php } ?> <?php wp_reset_postdata(); ?> </div><!-- /entry-content --> <?php } genesis();
July 11, 2017 at 3:47 pm #209002Brad DaltonParticipantHello Maffy
Happy to point you in the right direction.
They will if you create a taxonomy-resources-type.php template which uses the WordPress Template Hierarchy.
I suggest you add support for taxonomy types rather than use categories.
Here's some code you can use as a guide to create the CPT and Taxonomy support. Swap out all instances of Portfolio with the name of your CPT
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.