Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created August 10, 2016 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/778f2e04672b0aa97f76886c77cfdb35 to your computer and use it in GitHub Desktop.
Save billerickson/778f2e04672b0aa97f76886c77cfdb35 to your computer and use it in GitHub Desktop.
<?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