There are lots of resources that explain how to create a Custom Post Type, but few go into detail on how to display. This presentation does both, all from a Designer's perspective.
20. It’s not a post. But it acts like a post
It displays content on a Single post page
It can display content on an Archive page
It’s not a page. But it acts like a page
It’s not heirarchical
You can assign it a page template
Normally, it can’t access categories that were
created by the Post
21. D ispl a y : T e m pl a t e s
single.php
Start with 3 exisiting files
archive.php
taxonomy.php
22. D ispl a y : T e m pl a t e s
single-portfolio.php
Add a slug to the name
archive-portfolio.php
taxonomy-work_type.php
24. th e m a g ic o f :
Template Hierarchy
a r chi v e p o st :
si n g l e p o st :
T a x o n o m y p o st :
archive-portfolio.php
single-portfolio.php
taxonomy-work_type-logo.php
archive.php
single.php
taxonomy-work_type.php
index.php
index.php
taxonomy.php
archive.php
index.php
25. SoWhy?
To make your CPT posts look different
from your single and archive posts
that appear in your blog.
26. D ispl a y : M o di f y th e t e m pl a t e
taxonomy-work_type.php
Page Title
Thumbnail
Post Title
29. D ispl a y : m o di f y th e T e m pl a t e s
https://codex.wordpress.org/
the_post_thumbnail(); // without parameter -> ‘post-thumbnail’
the_post_thumbnail(‘thumbnail’); // Thumbnail (default 150px x 150px max)
the_post_thumbnail(‘medium’); // Medium resolution (default 300px x 300px max)
the_post_thumbnail(‘large’); // Large resolution (default 640px x 640px max)
the_post_thumbnail(‘full’); // Full resolution (original size uploaded)
functions.php
//Enable support for Post Thumbnails
add_image_size( ‘portfolio-thumb’, 250, 250, true );
31. D ispl a y : C S S a n d B o d y cl a ss
H1.page-title
32. D ispl a y : C S S a n d B o d y cl a ss
Use chrome inspector tool to find body class
class = .post-type-archive-portfolio
33. D ispl a y : C S S a n d B o d y cl a ss
.post-type-archive-portfolio #primary h1.entry-title
{
font-weight:700; font-size:15px; letter-spacing: .15em;
border: 1px #ccc dotted; padding: 20px;
}
38. Another way to Display:
Page Template!
bye bye archive-portfolio.php
39. Why a Page?
More control with design
Easier to add to a menu
Easier to add custom sidebars
40. D ispl a y : T e m pl a t e s / P AGE
Look Familiar?
Duplic ate:
page.php
Rename:
page-portfolio.php
/* Template Name: Portfolio Page*/
Op en an d Add:
42. D ispl a y : T e m pl a t e s / P a g e
Add php code to the template
Use a Plugin: Grid FX
<?php
$args = array( ‘post_type’ => ‘portfolio’, ‘posts_per_page’ => 10 );
$loop = new WP_Query($args);
?>
<?php
while ( $loop->have_posts() ) : $loop->the_post();
get_template_part( ‘content’, get_post_format() );
endwhile;
twentyfourteen_paging_nav();
wp_reset_postdata();
?>
OR
43. D ispl a y : T e m pl a t e s
Using the plugin Grid FX