Created
March 8, 2016 07:18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/********************************************* | |
OBJECTIVE | |
********************************************** | |
The goal is to create either a series of archive templates | |
OR a function called by shortcode that will display a list | |
of CPT entries based on the assigned custom taxonomy. | |
The CPT code below (functions.php) works. What I cannot | |
figure out is how to build the archives, which I want | |
to look like this: | |
<TITLE> | |
<DESCRIPTION> | |
03/08/16 - Contest #5 | |
03/04/16 - Contest #4 | |
03/02/16 - Contest #3 | |
02/29/16 - Contest #2 | |
02/15/16 - Contest #1 | |
Where the list is all of the CPTs with a given | |
assigned taxonomy (active/archived). | |
I've tried using tutorial snippets to build archive | |
pages using the WP conventions like: | |
archive-contest.php | |
taxonomy-contest-details-archive.php | |
Example code are included below. However, they do not | |
seem to work. And, as I think of it, a better use | |
case would be just to make a page and call the | |
archive listing with a shortcode. That would allow | |
me to keep the pages within the page/aubpage permalink | |
model. | |
**********************************************/ | |
/********************************************* | |
functions.php | |
**********************************************/ | |
/* Contest CPT :: Initiate CPT | |
**********************************************/ | |
function be_register_contest_post_type() { | |
$labels = array( | |
'name' => 'Contests', | |
'singular_name' => 'Contest', | |
'add_new' => 'Add New', | |
'add_new_item' => 'Add New Contest', | |
'edit_item' => 'Edit Contest', | |
'new_item' => 'New Contest', | |
'view_item' => 'View Contest', | |
'search_items' => 'Search Contests', | |
'not_found' => 'No contests found', | |
'not_found_in_trash' => 'No contests found in trash.', | |
'parent_item_colon' => '', | |
'menu_name' => 'Contests' | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'publicly_queryable' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'query_var' => true, | |
'rewrite' => true, | |
'capability_type' => 'post', | |
'has_archive' => true, | |
'hierarchical' => false, | |
'menu_icon' => 'dashicons-tickets', | |
'menu_position' => null, | |
'supports' => array('title','editor'), | |
'taxonomies' => array( 'contest-status' ), | |
); | |
register_post_type( 'contests', $args ); | |
} | |
add_action( 'init', 'be_register_contest_post_type' ); | |
/* Contest CPT :: Add Taxonomy | |
**********************************************/ | |
function be_register_contest_status_taxonomy() { | |
$labels = array( | |
'name' => 'Contest Status', | |
'singular_name' => 'Contest Status', | |
'search_items' => 'Search Contest Status', | |
'all_items' => 'All Contest Status', | |
'edit_item' => 'Edit Contest Status', | |
'update_item' => 'Update Contest Status', | |
'add_new_item' => 'Add New Contest Status', | |
'new_item_name' => 'New Contest Status Name', | |
'menu_name' => 'Contest Status' | |
); | |
register_taxonomy( 'contest-status', array('contests'), | |
array( | |
'hierarchical' => true, | |
'labels' => $labels, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'contest-status' ), | |
) | |
); | |
} | |
add_action( 'init', 'be_register_contest_status_taxonomy' ); | |
/* Add Archive Settings to Contests CPT | |
**********************************************/ | |
add_post_type_support( 'contests', 'genesis-cpt-archives-settings' ); | |
/********************************************* | |
archive-contests.php | |
**********************************************/ | |
//* Force full width content layout | |
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' ); | |
//* Remove the breadcrumb navigation | |
remove_action( 'genesis_before_loop', 'genesis_do_breadcrumbs' ); | |
//* Remove the post info function | |
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 ); | |
//* Add custom body class to the head | |
add_filter( 'body_class', 'wpsites_add_games_body_class' ); | |
function wpsites_add_games_body_class( $classes ) { | |
$classes[] = 'wpsites-pro-games'; | |
return $classes; | |
} | |
//* Remove the post meta function | |
remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); | |
genesis(); | |
/********************************************* | |
taxonomy-contest-status-archive | |
**********************************************/ | |
function pf_blog_archive_body_class( $classes ) { | |
$classes[] = 'blog-archive'; | |
return $classes; | |
} | |
add_filter( 'body_class', 'pf_blog_archive_body_class' ); | |
/* Custom Post meta on single posts */ | |
add_filter( 'genesis_post_info', 'pf_post_info_filter' ); | |
/* Remove tags on archive pages */ | |
remove_action( 'genesis_entry_footer', 'genesis_post_meta' ); | |
genesis(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment