Skip to content

Instantly share code, notes, and snippets.

@About2git
Forked from srikat/functions.php
Created February 15, 2015 22:21
Show Gist options
  • Save About2git/0cc22bc8ab1080ae5f84 to your computer and use it in GitHub Desktop.
Save About2git/0cc22bc8ab1080ae5f84 to your computer and use it in GitHub Desktop.
Adding Portfolio Type taxonomy in Minimum Pro
<?php
//* Start the engine
include_once( get_template_directory() . '/lib/init.php' );
//* Set Localization (do not remove)
load_child_theme_textdomain( 'minimum', apply_filters( 'child_theme_textdomain', get_stylesheet_directory() . '/languages', 'minimum' ) );
//* Child theme (do not remove)
define( 'CHILD_THEME_NAME', __( 'Minimum Pro Theme', 'minimum' ) );
define( 'CHILD_THEME_URL', 'http://my.studiopress.com/themes/minimum/' );
define( 'CHILD_THEME_VERSION', '3.0' );
//* Add HTML5 markup structure
add_theme_support( 'html5' );
//* Add viewport meta tag for mobile browsers
add_theme_support( 'genesis-responsive-viewport' );
//* Enqueue scripts
add_action( 'wp_enqueue_scripts', 'minimum_enqueue_scripts' );
function minimum_enqueue_scripts() {
wp_enqueue_script( 'minimum-responsive-menu', get_bloginfo( 'stylesheet_directory' ) . '/js/responsive-menu.js', array( 'jquery' ), '1.0.0' );
wp_enqueue_style( 'minimum-google-fonts', '//fonts.googleapis.com/css?family=Roboto:300,400|Roboto+Slab:300,400', array(), CHILD_THEME_VERSION );
}
//* Add new image sizes
add_image_size( 'portfolio', 540, 340, TRUE );
//* Add support for custom background
add_theme_support( 'custom-background', array( 'wp-head-callback' => '__return_false' ) );
//* Add support for custom header
add_theme_support( 'custom-header', array(
'width' => 320,
'height' => 60,
'header-selector' => '.site-title a',
'header-text' => false
) );
//* Add support for structural wraps
add_theme_support( 'genesis-structural-wraps', array(
'header',
'site-tagline',
'nav',
'subnav',
'home-featured',
'site-inner',
'footer-widgets',
'footer'
) );
//* Add support for 3-column footer widgets
add_theme_support( 'genesis-footer-widgets', 3 );
//* Unregister layout settings
genesis_unregister_layout( 'content-sidebar-sidebar' );
genesis_unregister_layout( 'sidebar-content-sidebar' );
genesis_unregister_layout( 'sidebar-sidebar-content' );
//* Unregister secondary sidebar
unregister_sidebar( 'sidebar-alt' );
//* Create Portfolio Type custom taxonomy
add_action( 'init', 'minimum_type_taxonomy' );
function minimum_type_taxonomy() {
register_taxonomy( 'portfolio-type', 'portfolio',
array(
'labels' => array(
'name' => _x( 'Types', 'taxonomy general name', 'minimum' ),
'add_new_item' => __( 'Add New Portfolio Type', 'minimum' ),
'new_item_name' => __( 'New Portfolio Type', 'minimum' ),
),
'exclude_from_search' => true,
'has_archive' => true,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'portfolio-type', 'with_front' => false ),
'show_ui' => true,
'show_tagcloud' => false,
)
);
}
//* Create portfolio custom post type
add_action( 'init', 'minimum_portfolio_post_type' );
function minimum_portfolio_post_type() {
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __( 'Portfolio', 'minimum' ),
'singular_name' => __( 'Portfolio', 'minimum' ),
),
// 'exclude_from_search' => true,
'has_archive' => true,
'hierarchical' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/images/icons/portfolio.png',
'public' => true,
'rewrite' => array( 'slug' => 'portfolio' ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'genesis-seo', 'genesis-cpt-archives-settings' ),
'taxonomies' => array( 'portfolio-type' ),
)
);
}
//* Add Portfolio Type Taxonomy to columns
add_filter( 'manage_taxonomies_for_portfolio_columns', 'portfolio_columns' );
function portfolio_columns( $taxonomies ) {
$taxonomies[] = 'portfolio-type';
return $taxonomies;
}
//* Remove site description
remove_action( 'genesis_site_description', 'genesis_seo_site_description' );
//* Reposition the primary navigation menu
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_after_header', 'genesis_do_nav', 15 );
//* Reposition the secondary navigation menu
remove_action( 'genesis_after_header', 'genesis_do_subnav' );
add_action( 'genesis_footer', 'genesis_do_subnav', 7 );
//* Reduce the secondary navigation menu to one level depth
add_filter( 'wp_nav_menu_args', 'minimum_secondary_menu_args' );
function minimum_secondary_menu_args( $args ){
if( 'secondary' != $args['theme_location'] )
return $args;
$args['depth'] = 1;
return $args;
}
//* Add the site tagline section
add_action( 'genesis_after_header', 'minimum_site_tagline' );
function minimum_site_tagline() {
printf( '<div %s>', genesis_attr( 'site-tagline' ) );
genesis_structural_wrap( 'site-tagline' );
printf( '<div %s>', genesis_attr( 'site-tagline-left' ) );
printf( '<p %s>%s</p>', genesis_attr( 'site-description' ), esc_html( get_bloginfo( 'description' ) ) );
echo '</div>';
printf( '<div %s>', genesis_attr( 'site-tagline-right' ) );
genesis_widget_area( 'site-tagline-right' );
echo '</div>';
genesis_structural_wrap( 'site-tagline', 'close' );
echo '</div>';
}
//* Modify the size of the Gravatar in the author box
add_filter( 'genesis_author_box_gravatar_size', 'minimum_author_box_gravatar' );
function minimum_author_box_gravatar( $size ) {
return 144;
}
//* Modify the size of the Gravatar in the entry comments
add_filter( 'genesis_comment_list_args', 'minimum_comments_gravatar' );
function minimum_comments_gravatar( $args ) {
$args['avatar_size'] = 96;
return $args;
}
//* Change the number of portfolio items to be displayed (props Bill Erickson)
add_action( 'pre_get_posts', 'minimum_portfolio_items' );
function minimum_portfolio_items( $query ) {
if ( $query->is_main_query() && !is_admin() && is_post_type_archive( 'portfolio' ) ) {
$query->set( 'posts_per_page', '6' );
}
}
//* Register widget areas
genesis_register_sidebar( array(
'id' => 'site-tagline-right',
'name' => __( 'Site Tagline Right', 'minimum' ),
'description' => __( 'This is the site tagline right section.', 'minimum' ),
) );
genesis_register_sidebar( array(
'id' => 'home-featured-1',
'name' => __( 'Home Featured 1', 'minimum' ),
'description' => __( 'This is the home featured 1 section.', 'minimum' ),
) );
genesis_register_sidebar( array(
'id' => 'home-featured-2',
'name' => __( 'Home Featured 2', 'minimum' ),
'description' => __( 'This is the home featured 2 section.', 'minimum' ),
) );
genesis_register_sidebar( array(
'id' => 'home-featured-3',
'name' => __( 'Home Featured 3', 'minimum' ),
'description' => __( 'This is the home featured 3 section.', 'minimum' ),
) );
genesis_register_sidebar( array(
'id' => 'home-featured-4',
'name' => __( 'Home Featured 4', 'minimum' ),
'description' => __( 'This is the home featured 4 section.', 'minimum' ),
) );
//* Show Portfolio Type hyperlinked terms on Portfolio single entry pages
add_filter( 'genesis_post_meta', 'sk_post_meta_filter' );
function sk_post_meta_filter($post_meta) {
if ( ! is_singular( 'portfolio' ) )
return;
$post_meta = '[post_terms taxonomy="portfolio-type"]';
return $post_meta;
}
//* Create Portfolio Type custom taxonomy
add_action( 'init', 'minimum_type_taxonomy' );
function minimum_type_taxonomy() {
register_taxonomy( 'portfolio-type', 'portfolio',
array(
'labels' => array(
'name' => _x( 'Types', 'taxonomy general name', 'minimum' ),
'add_new_item' => __( 'Add New Portfolio Type', 'minimum' ),
'new_item_name' => __( 'New Portfolio Type', 'minimum' ),
),
'exclude_from_search' => true,
'has_archive' => true,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'portfolio-type', 'with_front' => false ),
'show_ui' => true,
'show_tagcloud' => false,
)
);
}
//* Create portfolio custom post type
add_action( 'init', 'minimum_portfolio_post_type' );
function minimum_portfolio_post_type() {
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __( 'Portfolio', 'minimum' ),
'singular_name' => __( 'Portfolio', 'minimum' ),
),
// 'exclude_from_search' => true,
'has_archive' => true,
'hierarchical' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/images/icons/portfolio.png',
'public' => true,
'rewrite' => array( 'slug' => 'portfolio' ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'genesis-seo', 'genesis-cpt-archives-settings' ),
'taxonomies' => array( 'portfolio-type' ),
)
);
}
//* Add Portfolio Type Taxonomy to columns
add_filter( 'manage_taxonomies_for_portfolio_columns', 'portfolio_columns' );
function portfolio_columns( $taxonomies ) {
$taxonomies[] = 'portfolio-type';
return $taxonomies;
}
//* Show Portfolio Type hyperlinked terms on Portfolio single entry pages
add_filter( 'genesis_post_meta', 'sk_post_meta_filter' );
function sk_post_meta_filter($post_meta) {
if ( ! is_singular( 'portfolio' ) )
return;
$post_meta = '[post_terms taxonomy="portfolio-type"]';
return $post_meta;
}
//* Create portfolio custom post type
add_action( 'init', 'minimum_portfolio_post_type' );
function minimum_portfolio_post_type() {
register_post_type( 'portfolio',
array(
'labels' => array(
'name' => __( 'Portfolio', 'minimum' ),
'singular_name' => __( 'Portfolio', 'minimum' ),
),
'exclude_from_search' => true,
'has_archive' => true,
'hierarchical' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/images/icons/portfolio.png',
'public' => true,
'rewrite' => array( 'slug' => 'portfolio' ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'genesis-seo' ),
)
);
}
/* for Portfolio Type custom taxonomy's term archive page. Ex.: http://example.dev/portfolio-type/nature/
------------------------------------------------------------------------------------------------------ */
.tax-portfolio-type .entry {
float: left;
margin-bottom: 60px;
margin-bottom: 6rem;
width: 50%;
}
.tax-portfolio-type .entry:nth-of-type(2n) {
float: right;
padding-left: 30px;
padding-left: 3rem;
}
.tax-portfolio-type .entry:nth-of-type(2n+1) {
clear: left;
padding-right: 30px;
padding-right: 3rem;
}
@media only screen and (max-width: 1023px) {
.tax-portfolio-type .entry {
text-align: center;
}
}
@media only screen and (max-width: 768px) {
.tax-portfolio-type .entry {
width: 100%;
}
.tax-portfolio-type .entry:nth-of-type(2n),
.tax-portfolio-type .entry:nth-of-type(2n+1) {
float: none;
padding: 0;
}
}
<?php
/**
* This file adds the portfolio type taxonomy archive template to the Minimum Pro Theme.
*
* @author StudioPress
* @package Minimum Pro
* @subpackage Customizations
*/
//* 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', 5 );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
//* Remove the post content
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
//* Remove the post image
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
//* Add portfolio body class to the head
add_filter( 'body_class', 'minimum_add_portfolio_body_class' );
function minimum_add_portfolio_body_class( $classes ) {
$classes[] = 'minimum-pro-portfolio';
return $classes;
}
//* Add the featured image after post title
add_action( 'genesis_entry_header', 'minimum_portfolio_grid' );
function minimum_portfolio_grid() {
if ( $image = genesis_get_image( 'format=url&size=portfolio' ) ) {
printf( '<div class="portfolio-featured-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), $image, the_title_attribute( 'echo=0' ) );
}
}
//* Remove the post meta function
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