Custom post types used in Genesis child themes

Code used in Minimum Pro and Executive Pro

StudioPress have two Child Themes that contain custom post types: Minimum Pro and Executive Pro.

Minimum Pro Demo

Minimum Portfolio Post type
The first code contains the custom portfolio post type added to the Minimum Pro child theme functions.php file. Adding the code to your own child theme functions file will include a new sidebar item called Portfolio.

archive-portfolio.php
Creates a listing of your portfolio. The file is added to your child theme root folder.

single-portfolio.php
Creates a single page layout for each image. The file is added to your child theme root folder.

CSS code
I included the CSS code inside the style.css file that contains the word Portfolio. You can add it to your own stylesheet and modify it as you choose.

Below is the code for:
1. Code used inside the functions.php file.
2. Code used in the archive-portfolio.php file.
3. Code used inside the single-portfolio.php file.
4. Code used inside the style.css file.

functions.php code

//* Custom Post type code used inside the functions.php file inside the Minumum Pro Genesis child theme.
//* 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'           => 'dashicons-admin-page',
			'public'              => true,
			'rewrite'             => array( 'slug' => 'portfolio', 'with_front' => false ),
			'supports'            => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes', 'genesis-seo' ),
		)
	);
	
}

archive-portfolio.php code

<?php
/**
 * The custom portfolio post type archive template
 */

//* Force full width content layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );

//* Add even/odd post class
add_filter( 'post_class', 'minimum_even_odd_portfolio_post_class' );
function minimum_even_odd_portfolio_post_class( $classes ) {

	global $wp_query;
	$classes[] = ($wp_query->current_post % 2 == 0) ? 'portfolio-odd' : 'portfolio-even';
	return $classes;

}

//* Remove the entry meta in the entry header
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );

//* Remove the entry content
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );

//* Remove the entry image
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );

//* Add the featured image after post title
add_action( 'genesis_entry_content', 'minimum_portfolio_grid' );
function minimum_portfolio_grid() {

	if ( $image = genesis_get_image( 'format=url&size=portfolio' ) ) {
		printf( '<div class="portfolio-image"><a href="%s" rel="bookmark"><img src="%s" alt="%s" /></a></div>', get_permalink(), $image, the_title_attribute( 'echo=0' ) );

	}

}

//* Remove the entry meta in the entry footer
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );

//* Run the Genesis loop
genesis();

single-portfolio.php code

<?php
/**
 * The custom portfolio post type single post template
 */

//* Force full width content layout
add_filter( 'genesis_pre_get_option_site_layout', '__genesis_return_full_width_content' );

//* Remove the entry meta in the entry header
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );

//* Remove the author box on single posts
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 );

//* Remove the entry meta in the entry footer
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );

//* Remove the comments template
remove_action( 'genesis_after_entry', 'genesis_get_comments_template' );

//* Run the Genesis loop
genesis();

style.css code

//* CSS code that mentions the word portfolio used inside the style.css file inside the Genesis Minumum Pro child theme.
/* Titles
--------------------------------------------- */
.single-portfolio .entry-title {
	margin-bottom: 20px;
}

/* Entries
--------------------------------------------- */
.post-type-archive-portfolio .entry {
  	float: left;
  	margin-bottom: 60px;
  	width: 50%;
}

.post-type-archive-portfolio .entry:nth-of-type(2n) {
	float: right;
	padding-left: 30px;
}

.post-type-archive-portfolio .entry:nth-of-type(2n+1) {
  	clear: left;
	  padding-right: 30px;
}

.single-portfolio .entry {
	  text-align: center;
}

@media only screen and (max-width: 1023px) {
    .post-type-archive-portfolio .entry,
  	.site-header .title-area,
  	.site-header .search-form,
  	.site-header .widget-area,
  	.site-tagline-left,
  	.site-tagline-right {
    		text-align: center;
	  }
}	

@media only screen and (max-width: 768px) {
    .genesis-grid-even,
	  .genesis-grid-odd,
	  .post-type-archive-portfolio .entry {
	    	width: 100%;
  	}

  	.post-type-archive-portfolio .entry:nth-of-type(2n),
  	.post-type-archive-portfolio .entry:nth-of-type(2n+1) {
	    	float: none;
	    	padding: 0;
	  }
}	 

Executive Pro Demo

The code used in the Executive Pro is similar to Minimum Pro but contains a few more features such as taxonomy (a way to group posts similar to a category or tag). https://codex.wordpress.org/Taxonomies

Executive Pro Portfolio Post type
The first code contains the custom portfolio post type added to the Executive Pro child theme functions.php file. Adding the code to your own child theme functions file will include a new sidebar item called Portfolio.

archive-portfolio.php
Creates a listing of your portfolio. The file is added to your child theme root folder.

single-portfolio.php
Creates a single page layout for each image. The file is added to your child theme root folder.

CSS code
I included the CSS code inside the style.css file that contains the word Portfolio. You can add it to your own stylesheet and modify it as you choose.

Taxonomy (Bottom file).  The file is added to your child theme root folder.

functions.php code

//* Custom Post type code used inside the functions.php file inside the Executive Pro Genesis child theme.
//* Create Portfolio Type custom taxonomy
add_action( 'init', 'executive_type_taxonomy' );
function executive_type_taxonomy() {

	register_taxonomy( 'portfolio-type', 'portfolio',
		array(
			'labels' => array(
				'name'          => _x( 'Types', 'taxonomy general name', 'executive' ),
				'add_new_item'  => __( 'Add New Portfolio Type', 'executive' ),
				'new_item_name' => __( 'New Portfolio Type', 'executive' ),
			),
			'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', 'executive_portfolio_post_type' );
function executive_portfolio_post_type() {

	register_post_type( 'portfolio',
		array(
			'labels' => array(
				'name'          => __( 'Portfolio', 'executive' ),
				'singular_name' => __( 'Portfolio', 'executive' ),
			),
			'has_archive'  => true,
			'hierarchical' => true,
			'menu_icon'    => get_stylesheet_directory_uri() . '/lib/icons/portfolio.png',
			'public'       => true,
			'rewrite'      => array( 'slug' => 'portfolio', 'with_front' => false ),
			'supports'     => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', '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', 'executive_portfolio_columns' );
function executive_portfolio_columns( $taxonomies ) {

    $taxonomies[] = 'portfolio-type';
    return $taxonomies;

}

archive-portfolio.php code

<?php
/**
 * This file adds the custom portfolio post type archive template to the Executive Pro Theme.
 *
 * @author StudioPress
 * @package Executive 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 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', 'executive_add_portfolio_body_class' );
function executive_add_portfolio_body_class( $classes ) {
   $classes[] = 'executive-pro-portfolio';
   return $classes;
}

//* Add the featured image after post title
add_action( 'genesis_entry_header', 'executive_portfolio_grid' );
function executive_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();

single-portfolio.php code

<?php
/**
 * This file adds the custom portfolio post type single post template to the Executive Pro Theme.
 *
 * @author StudioPress
 * @package Executive 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 the author box on single posts
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 );

//* Remove the post meta function
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );

genesis();

style.css code

//* CSS code that mentions the word portfolio used inside the style.css file inside the Genesis Executive Pro child theme.
/* Content  */

.executive-pro-portfolio .content {
	padding: 40px 30px 0;
}


/* Titles
--------------------------------------------- */
.archive-title,
.widget-title,
.executive-pro-portfolio .entry-title {
   font-size: 16px;
   text-transform: uppercase;
   margin-bottom: 20px;
}

/* Portfolio
--------------------------------------------- */

.executive-pro-portfolio .portfolio {
	float: left;
	padding: 0 30px 30px;
	width: 33.33333333%;
}

.executive-pro-portfolio .portfolio:nth-of-type(3n+1) {
	clear: left;
}

.single-portfolio .content {
	text-align: center;
}

/* Entries
--------------------------------------------- */

.executive-pro-portfolio .entry,
.single-portfolio .entry {
	margin-bottom: 20px;
}

@media only screen and (max-width: 800px) {

	.five-sixths,
	.footer-widgets-1,
	.footer-widgets-2,
	.footer-widgets-3,
	.four-sixths,
	.home-middle .widget,
	.home-top .widget,
	.one-fourth,
	.one-half,
	.one-sixth,
	.one-third,
	.executive-pro-portfolio .portfolio,
	.three-fourths,
	.three-sixths,
	.two-fourths,
	.two-sixths,
	.two-thirds {
		margin: 0;
		width: 100%;
	}
	
	.home-middle,
	.home-top,
	.executive-pro-portfolio .portfolio {
		text-align: center;
	}
	
	.executive-pro-portfolio .portfolio {
		padding: 0 0 30px;
	}
	
}

taxonomy-portfolio-type.php code

<?php
/**
 * This file adds the portfolio type taxonomy archive template to the Executive Pro Theme.
 *
 * @author StudioPress
 * @package Executive 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 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', 'executive_add_portfolio_body_class' );
function executive_add_portfolio_body_class( $classes ) {

   $classes[] = 'executive-pro-portfolio';
   return $classes;
   
}

//* Add the featured image after post title
add_action( 'genesis_entry_header', 'executive_portfolio_grid' );
function executive_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();
Share the article:

One comment

  1. This piece of code and some of the css for the genesis grid was forgotten.
    Adding the comment.

    Functions
    //* Add new image sizes
    add_image_size( ‘portfolio’, 540, 340, TRUE );

    CSS
    .genesis-grid-even,
    .genesis-grid-odd {
    border-bottom: 1px solid #f5f5f5;
    margin-bottom: 30px;
    margin-bottom: 3rem;
    padding: 0;
    width: 47%;
    }

    .genesis-grid-even {
    float: right;
    }

    .genesis-grid-odd {
    clear: both;
    float: left;
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

4 × one =