Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active March 17, 2016 19:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srikat/acd6f7a59b35986eb977 to your computer and use it in GitHub Desktop.
Save srikat/acd6f7a59b35986eb977 to your computer and use it in GitHub Desktop.
How to change Portfolio CPT to Communities in Minimum Pro. http://sridharkatakam.com/change-portfolio-cpt-communities-minimum-pro/
<?php
/**
* The custom communities 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_header', 'sk_communities_grid' );
function sk_communities_grid() {
if ( has_post_thumbnail() ) {
$image = genesis_get_image( 'format=url&size=communities' );
} else {
$image = get_stylesheet_directory_uri() .'/images/default-image.gif"';
}
printf( '<div class="communities-featured-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();
//* Add new image sizes
add_image_size( 'portfolio', 540, 340, TRUE );
//* Add new image size
add_image_size( 'communities', 540, 340, true );
//* 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' ),
)
);
}
//* Create communities custom post type
add_action( 'init', 'sk_communities_post_type' );
function sk_communities_post_type() {
register_post_type( 'communities',
array(
'labels' => array(
'name' => __( 'Community', 'minimum' ),
'singular_name' => __( 'Community', 'minimum' ),
),
'exclude_from_search' => true,
'has_archive' => true,
'hierarchical' => true,
'menu_icon' => 'dashicons-admin-page',
'public' => true,
'rewrite' => array( 'slug' => 'communities', 'with_front' => false ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes', 'genesis-seo', 'genesis-cpt-archives-settings' ),
)
);
}
//* 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' );
}
}
//* Change the number of communities items to be displayed (props Bill Erickson)
add_action( 'pre_get_posts', 'minimum_communities_items' );
function minimum_communities_items( $query ) {
if ( $query->is_main_query() && !is_admin() && is_post_type_archive( 'communities' ) ) {
$query->set( 'posts_per_page', '6' );
}
}
<?php
/**
* The custom communities 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 );
//* Display Featured image (if present) below title
add_action( 'genesis_entry_header', 'sk_display_featured_image' );
function sk_display_featured_image() {
if ( ! has_post_thumbnail() ) {
return;
}
echo '<div class="single-community-image">';
genesis_image();
echo '</div>';
}
//* Remove the author box on single posts
remove_action( 'genesis_after_entry', 'genesis_do_author_box_single', 8 );
//* Previous and Next Post navigation
add_action('genesis_after_entry', 'sk_custom_post_nav');
function sk_custom_post_nav() {
echo '<div class="prev-next-post-links">';
previous_post_link('<div class="previous-post-link">&laquo; %link</div>', '<strong>%title</strong>' );
next_post_link('<div class="next-post-link">%link &raquo;</div>', '<strong>%title</strong>' );
echo '</div>';
}
//* 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();
.single-community-image {
margin-bottom: 20px;
}
.prev-next-post-links {
overflow: hidden;
margin-bottom: 40px;
}
.previous-post-link {
float: left;
}
.next-post-link {
float: right;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment