Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active July 13, 2018 21:55
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 danielpataki/87dda87e6160ac22bf27e2b8deb933a5 to your computer and use it in GitHub Desktop.
Save danielpataki/87dda87e6160ac22bf27e2b8deb933a5 to your computer and use it in GitHub Desktop.
Custom post type templates
.site-content-contain {
position: static;
}
#review-head {
position: absolute;
top:55px;
left:0px;
padding:22px;
color:#fff;
width:100%;
text-align:center;
background: rgba(0,0,0,0.3);
}
#review-head h1 {
font-weight: 300;
margin:0px;
padding:0px;
}
#review-head small {
color: rgba(255,255,255,0.5);
font-weight: 500;
text-transform: uppercase;
font-size:11px;
letter-spacing: 1px
}
<header id='review-head'>
<h1><?php the_title() ?></h1>
<small>Full Video Review</small>
</header>
add_action( 'init', 'cptt_custom_post_types' );
function cptt_custom_post_types() {
register_post_type( 'game',
array(
'labels' => array(
'name' => __( 'Games' ),
'singular_name' => __( 'Game' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'thumbnail' ),
'menu_icon' => 'dashicons-laptop'
)
);
}
<?php
add_action( 'wp_enqueue_scripts', 'cptt_assets' );
function cptt_assets() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', array( 'parent-style' ));
}
<?php get_template_part( 'template-parts/header/header', 'image' ); ?>
/*
Theme Name: Custom Post Type Template Example
Theme URI: http://danielpataki.com
Description: An example theme that utilizes custom post type templates
Author: Daniel Pataki
Author URI: http://danielpataki.com
Template: twentyseventeen
Version: 1.0.0
*/
<?php
/*
Template Name: Game Review
Template Post Type: game
*/
get_header( 'review' ); ?>
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
/* Start the Loop */
while ( have_posts() ) : the_post();
get_template_part( 'template-parts/game/content', 'review' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
the_post_navigation( array(
'prev_text' => '<span class="screen-reader-text">' . __( 'Previous Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Previous', 'twentyseventeen' ) . '</span> <span class="nav-title"><span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '</span>%title</span>',
'next_text' => '<span class="screen-reader-text">' . __( 'Next Post', 'twentyseventeen' ) . '</span><span aria-hidden="true" class="nav-subtitle">' . __( 'Next', 'twentyseventeen' ) . '</span> <span class="nav-title">%title<span class="nav-title-icon-wrapper">' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ) . '</span></span>',
) );
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
</div><!-- .wrap -->
<?php get_footer();
<?php
/*
Template Name: Game Review
Template Post Type: game
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment