-
-
Save billerickson/778f2e04672b0aa97f76886c77cfdb35 to your computer and use it in GitHub Desktop.
This file contains 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 | |
add_action( ‘init’, ‘create_custom_post_type’ ); | |
function create_custom_post_type() { | |
$labels = array( | |
‘name’ => __( ‘portfolio’ ), | |
‘singular_name’ => __( ‘portfolio’ ), | |
‘all_items’ => __(‘All Portfolios’), | |
‘add_new’ => _x(‘Add new Portfolio’, ‘Portfolios’), | |
‘add_new_item’ => __(‘Add new Portfolio’), | |
‘edit_item’ => __(‘Edit Portfolio’), | |
‘new_item’ => __(‘New Portfolio’), | |
‘view_item’ => __(‘View Portfolio’), | |
‘search_items’ => __(‘Search in Portfolios’), | |
‘not_found’ => __(‘No Portfolios found’), | |
‘not_found_in_trash’ => __(‘No Portfolios found in trash’), | |
‘parent_item_colon’ => ” | |
); | |
$args = array( | |
‘labels’ => $labels, | |
‘public’ => true, | |
‘has_archive’ => true, | |
‘menu_icon’ => ‘/f318’, | |
‘rewrite’ => array(‘slug’ => ‘product’), | |
‘taxonomies’ => array( ‘category’, ‘post_tag’ ), | |
‘supports’ => array( ‘title’, ‘editor’, ‘thumbnail’ , ‘custom-fields’, ‘excerpt’, ‘comments’, ‘genesis-cpt-archives-settings’ ) | |
); | |
register_post_type( ‘portfolio’, $args); | |
} | |
function be_portfolio_template( $template ) { | |
if( is_tax( array( ‘portfolio_category’, ‘portfolio_tag’ ) ) ) | |
$template = get_query_template( ‘archive-portfolio’ ); | |
return $template; | |
} | |
add_filter( ‘template_include’, ‘be_portfolio_template’ ); | |
// add_filter( ‘genesis_attr_site-description’, ‘abte_add_site_description_class’ ); | |
/** | |
* Add class for screen readers to site description. | |
* | |
* Unhook this if you’d like to show the site description on Portfolio CPT archive. | |
* | |
* @since 1.0.0 | |
* | |
* @param array $attributes Existing HTML attributes for site description element. | |
* @return string Amended HTML attributes for site description element. | |
*/ | |
function abte_add_site_description_class( $attributes ) { | |
if ( is_post_type_archive( ‘portfolio’ ) ) { | |
$attributes[‘class’] .= ‘ screen-reader-text’; | |
} | |
return $attributes; | |
} | |
add_action( ‘pre_get_posts’, ‘sk_change_portfolio_posts_per_page’ ); | |
/** | |
* Change Posts Per Page for Portfolio Archive | |
* | |
* @author Bill Erickson | |
* @link http://www.billerickson.net/customize-the-wordpress-query/ | |
* @param object $query data | |
* | |
*/ | |
function sk_change_portfolio_posts_per_page( $query ) { | |
if( $query->is_main_query() && !is_admin() && is_post_type_archive( ‘portfolio’) ) { | |
$query->set( ‘posts_per_page’, ‘999’); | |
} | |
} | |
function be_portfolio_query( $query ) { | |
if( $query->is_main_query() && !is_admin() && ( is_post_type_archive( ‘portfolio’ ) || is_tax( array( ‘portfolio_category’, ‘portfolio_tag’ ) ) ) ) { | |
$query->set( ‘orderby’, ‘menu_order’ ); | |
$query->set( ‘order’, ‘ASC’ ); | |
} | |
} | |
add_action( ‘pre_get_posts’, ‘be_portfolio_query’ ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment