SlideShare a Scribd company logo
Building a Portfolio With Custom
           Post Types
           Alex Blackie
             (x96design)
Slidemap
●   Define custom post types
●   Basic implementation (code walk-through)
●   Featured Images (thumbnails)
●   Live demo
●   Questions
●   Download link
What are Custom Post Types?


●   A way to add custom streams of content
      ● Photos, Podcasts, Screencasts...

      ● A blog outside of the blog
So...


WordPress Custom Post Types can be used for
           your Portfolio entries.
How It Works
●   WordPress
      –   Project Custom Post Type
           ●   Client taxonomy
                 – Clients
           ●   'Projects' entries
                 – Portfolio items
Benefits
●   Flexible
       –   Ability to extend
       –   Relate taxonomies between custom post types
●   Organized
       –   Clients are organized under their own section and can
           have multiple projects under them.
The Code
functions.php /   add_action()



add_action('init', 'create_post_type');
add_action('init', 'create_post_type_taxonomies');
functions.php /   register_post_type()
                                              Output:
function create_post_type() {
  register_post_type( 'projects',
    array(
      'labels' => array(
        'name' => __( 'Projects' ),
        'singular_name' => __( 'Project' ),
       ),
       'public' => true,
       'rewrite' => array('slug' => 'projects'),
       'supports' => array('title', 'custom-fields',
'editor', 'revisions')
    )
  );
}
functions.php /   register_post_type_taxonomy()
 function create_post_type_taxonomies() {
   $labels = array(
      'name'          => _x( 'Clients', 'taxonomy general name' ),
      'singular_name' => _x( 'Client', 'taxonomy singular name' ),
      'search_items'      => __( 'Search Clients' ),
      'all_items'         => __( 'All Clients' ),
      'parent_item'       => __( 'Parent Client' ),          Output:
      'parent_item_colon'=> __( 'Parent Client:' ),
      'edit_item'          => __( 'Edit Client' ),
      'update_item'        => __( 'Update Client' ),
      'add_new_item'       => __( 'Add New Client' ),
      'new_item_name'      => __( 'New Client Name' ),
   );
   register_taxonomy('client', array('projects'), array(
      'hierarchical' => true,
      'labels' => $labels,
      'show_ui' => true,
      'query_var' => true,
      'rewrite' => array( 'slug' => 'clients' ),
   ));
 }
portfolio-list.php
<?php
   /* Template Name: Portfolio Gallery */
   get_header();
   query_posts(array('post_type' => 'projects'));
?>
<ul>
<?php
   if(have_posts()): while(have_posts()): the_post();
?>
   <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?
></a></li>
<?php
   endwhile; else:
?>
   <li>No Entries Found.</li>
<?php
   endif;
?>
</ul>
<?php
   get_footer();
single-projects.php
<?php
   get_header();
   if(have_posts()): the_post();
?>
           <h1 class="page-title"><?php
the_title(); ?></h1>
           <?php the_content(); ?>
<?php
   else:
     // 404 message
   endif;
   get_footer();
Phew.
Making it “Pop”
●   Post Thumbnails
      –   Built into WordPress
      –   Integrated
      –   Easy to use
      –   Attaches thumbnails to posts
functions.php
add_theme_support('post-thumbnails');
function create_post_type() {
     register_post_type( 'projects',
          array(
               'labels' => array(
                    'name' => __( 'Projects' ),
                    'singular_name' => __( 'Project' ),
               ),
               'public' => true,
               'rewrite' => array('slug' => 'projects'),
              'supports' => array('title', 'custom-fields', 'editor', 'revisions',   'thumbnail')
         )
    );
}



                                                  Output:
portfolio-list.php
<?php
   /*Template Name: Portfolio Gallery */
   get_header();
   query_posts(array('post_type' => 'projects'));
   if(have_posts()): while(have_posts()): the_post();
?>
   <article class="project">
     <a href="<?php the_permalink(); ?>"><?php echo
get_the_post_thumbnail($page->ID, array('400', '300'); ?></a>
   </article>
<?php
   endwhile; else:
?>
   <h1>No Entries Found.</h1>
   <p>Uh-oh.</p>
<?php
   endif;
   get_footer();
single-projects.php
<?php
   get_header();
   if(have_posts()): the_post();
?>
           <h1 class="page-title"><?php the_title(); ?></h1>
           <aside>
             <?php echo get_the_post_thumbnail($page->ID, array('400',
'300'); ?>
           </aside>
           <div class="wraparound">
             <?php the_content(); ?>
           </div><!-- end .wraparound -->
<?php
   else:
     // 404 message
   endif;
   get_footer();
Live Demo
Questions?
Download This




       x96design.com/other/wcv11

●   All source code for functions.php, single-
    project.php, and project-list.php.
●   My presentation (slides) for reference.
Stalk Me

@x96design on Twitter

   X96Design.com

alex@x96design.com

More Related Content

What's hot (20)

12. edit record
12. edit record12. edit record
12. edit record
Razvan Raducanu, PhD
 
Let's write secure Drupal code!
Let's write secure Drupal code!Let's write secure Drupal code!
Let's write secure Drupal code!
Balázs Tatár
 
Backbone - TDC 2011 Floripa
Backbone - TDC 2011 FloripaBackbone - TDC 2011 Floripa
Backbone - TDC 2011 Floripa
Rafael Felix da Silva
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
Rafael Felix da Silva
 
How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patterns
Samuel ROZE
 
8. vederea inregistrarilor
8. vederea inregistrarilor8. vederea inregistrarilor
8. vederea inregistrarilor
Razvan Raducanu, PhD
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
Samuel ROZE
 
Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011Ruby - Design patterns tdc2011
Ruby - Design patterns tdc2011
Rafael Felix da Silva
 
So S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better CodeSo S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better Code
Neil Crookes
 
Михаил Крайнюк. Form api: ajax-commands
Михаил Крайнюк. Form api: ajax-commandsМихаил Крайнюк. Form api: ajax-commands
Михаил Крайнюк. Form api: ajax-commands
Ksenia Rogachenko
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
Rafael Dohms
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
Fabien Potencier
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
Leonardo Proietti
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
Rafael Dohms
 
Cloud Entwicklung mit Apex
Cloud Entwicklung mit ApexCloud Entwicklung mit Apex
Cloud Entwicklung mit Apex
Aptly GmbH
 
20. CodeIgniter edit images
20. CodeIgniter edit images20. CodeIgniter edit images
20. CodeIgniter edit images
Razvan Raducanu, PhD
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
Eyal Vardi
 
WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...
WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...
WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...
allilevine
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
Leonardo Proietti
 
Let's write secure Drupal code!
Let's write secure Drupal code!Let's write secure Drupal code!
Let's write secure Drupal code!
Balázs Tatár
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
Rafael Felix da Silva
 
How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patterns
Samuel ROZE
 
CQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony applicationCQRS and Event Sourcing in a Symfony application
CQRS and Event Sourcing in a Symfony application
Samuel ROZE
 
So S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better CodeSo S.O.L.I.D Fu - Designing Better Code
So S.O.L.I.D Fu - Designing Better Code
Neil Crookes
 
Михаил Крайнюк. Form api: ajax-commands
Михаил Крайнюк. Form api: ajax-commandsМихаил Крайнюк. Form api: ajax-commands
Михаил Крайнюк. Form api: ajax-commands
Ksenia Rogachenko
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHP Yo...
Rafael Dohms
 
Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)Be RESTful (Symfony Camp 2008)
Be RESTful (Symfony Camp 2008)
Fabien Potencier
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
Leonardo Proietti
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
Rafael Dohms
 
Cloud Entwicklung mit Apex
Cloud Entwicklung mit ApexCloud Entwicklung mit Apex
Cloud Entwicklung mit Apex
Aptly GmbH
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
Eyal Vardi
 
WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...
WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...
WordCamp Montreal 2015: Combining Custom Post Types, Fields, and Meta Boxes t...
allilevine
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
Leonardo Proietti
 

Similar to Building a Portfolio With Custom Post Types (20)

Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
references
 
Custom Post Types and Meta Fields
Custom Post Types and Meta FieldsCustom Post Types and Meta Fields
Custom Post Types and Meta Fields
Liton Arefin
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
Kyle Cearley
 
Extending WordPress. Making use of Custom Post Types
Extending WordPress. Making use of Custom Post TypesExtending WordPress. Making use of Custom Post Types
Extending WordPress. Making use of Custom Post Types
Utsav Singh Rathour
 
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
Mohamed Mosaad
 
Multilingualism makes better programmers
Multilingualism makes better programmersMultilingualism makes better programmers
Multilingualism makes better programmers
Alexander Varwijk
 
WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3
Mizanur Rahaman Mizan
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
Wade Austin
 
Django
DjangoDjango
Django
Kangjin Jun
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
Nile Flores
 
Separation of concerns - DPC12
Separation of concerns - DPC12Separation of concerns - DPC12
Separation of concerns - DPC12
Stephan Hochdörfer
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
fool2nd
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018
Adam Tomat
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
Joaquim Rocha
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Mike Schinkel
 
How to make a WordPress theme
How to make a WordPress themeHow to make a WordPress theme
How to make a WordPress theme
Hardeep Asrani
 
Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)
tompunk
 
Django Vs Rails
Django Vs RailsDjango Vs Rails
Django Vs Rails
Sérgio Santos
 
WordPress plugin #3
WordPress plugin #3WordPress plugin #3
WordPress plugin #3
giwoolee
 
Creatively creating custom post types! word sesh2
Creatively creating custom post types!  word sesh2Creatively creating custom post types!  word sesh2
Creatively creating custom post types! word sesh2
techvoltz
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
references
 
Custom Post Types and Meta Fields
Custom Post Types and Meta FieldsCustom Post Types and Meta Fields
Custom Post Types and Meta Fields
Liton Arefin
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
Kyle Cearley
 
Extending WordPress. Making use of Custom Post Types
Extending WordPress. Making use of Custom Post TypesExtending WordPress. Making use of Custom Post Types
Extending WordPress. Making use of Custom Post Types
Utsav Singh Rathour
 
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup CairoDig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
Mohamed Mosaad
 
Multilingualism makes better programmers
Multilingualism makes better programmersMultilingualism makes better programmers
Multilingualism makes better programmers
Alexander Varwijk
 
WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3
Mizanur Rahaman Mizan
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
Wade Austin
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
Nile Flores
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
fool2nd
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018
Adam Tomat
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
Joaquim Rocha
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Mike Schinkel
 
How to make a WordPress theme
How to make a WordPress themeHow to make a WordPress theme
How to make a WordPress theme
Hardeep Asrani
 
Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)Apostrophe (improved Paris edition)
Apostrophe (improved Paris edition)
tompunk
 
WordPress plugin #3
WordPress plugin #3WordPress plugin #3
WordPress plugin #3
giwoolee
 
Creatively creating custom post types! word sesh2
Creatively creating custom post types!  word sesh2Creatively creating custom post types!  word sesh2
Creatively creating custom post types! word sesh2
techvoltz
 

Building a Portfolio With Custom Post Types

  • 1. Building a Portfolio With Custom Post Types Alex Blackie (x96design)
  • 2. Slidemap ● Define custom post types ● Basic implementation (code walk-through) ● Featured Images (thumbnails) ● Live demo ● Questions ● Download link
  • 3. What are Custom Post Types? ● A way to add custom streams of content ● Photos, Podcasts, Screencasts... ● A blog outside of the blog
  • 4. So... WordPress Custom Post Types can be used for your Portfolio entries.
  • 5. How It Works ● WordPress – Project Custom Post Type ● Client taxonomy – Clients ● 'Projects' entries – Portfolio items
  • 6. Benefits ● Flexible – Ability to extend – Relate taxonomies between custom post types ● Organized – Clients are organized under their own section and can have multiple projects under them.
  • 8. functions.php / add_action() add_action('init', 'create_post_type'); add_action('init', 'create_post_type_taxonomies');
  • 9. functions.php / register_post_type() Output: function create_post_type() { register_post_type( 'projects', array( 'labels' => array( 'name' => __( 'Projects' ), 'singular_name' => __( 'Project' ), ), 'public' => true, 'rewrite' => array('slug' => 'projects'), 'supports' => array('title', 'custom-fields', 'editor', 'revisions') ) ); }
  • 10. functions.php / register_post_type_taxonomy() function create_post_type_taxonomies() { $labels = array( 'name' => _x( 'Clients', 'taxonomy general name' ), 'singular_name' => _x( 'Client', 'taxonomy singular name' ), 'search_items' => __( 'Search Clients' ), 'all_items' => __( 'All Clients' ), 'parent_item' => __( 'Parent Client' ), Output: 'parent_item_colon'=> __( 'Parent Client:' ), 'edit_item' => __( 'Edit Client' ), 'update_item' => __( 'Update Client' ), 'add_new_item' => __( 'Add New Client' ), 'new_item_name' => __( 'New Client Name' ), ); register_taxonomy('client', array('projects'), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'clients' ), )); }
  • 11. portfolio-list.php <?php /* Template Name: Portfolio Gallery */ get_header(); query_posts(array('post_type' => 'projects')); ?> <ul> <?php if(have_posts()): while(have_posts()): the_post(); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ? ></a></li> <?php endwhile; else: ?> <li>No Entries Found.</li> <?php endif; ?> </ul> <?php get_footer();
  • 12. single-projects.php <?php get_header(); if(have_posts()): the_post(); ?> <h1 class="page-title"><?php the_title(); ?></h1> <?php the_content(); ?> <?php else: // 404 message endif; get_footer();
  • 13. Phew.
  • 14. Making it “Pop” ● Post Thumbnails – Built into WordPress – Integrated – Easy to use – Attaches thumbnails to posts
  • 15. functions.php add_theme_support('post-thumbnails'); function create_post_type() { register_post_type( 'projects', array( 'labels' => array( 'name' => __( 'Projects' ), 'singular_name' => __( 'Project' ), ), 'public' => true, 'rewrite' => array('slug' => 'projects'), 'supports' => array('title', 'custom-fields', 'editor', 'revisions', 'thumbnail') ) ); } Output:
  • 16. portfolio-list.php <?php /*Template Name: Portfolio Gallery */ get_header(); query_posts(array('post_type' => 'projects')); if(have_posts()): while(have_posts()): the_post(); ?> <article class="project"> <a href="<?php the_permalink(); ?>"><?php echo get_the_post_thumbnail($page->ID, array('400', '300'); ?></a> </article> <?php endwhile; else: ?> <h1>No Entries Found.</h1> <p>Uh-oh.</p> <?php endif; get_footer();
  • 17. single-projects.php <?php get_header(); if(have_posts()): the_post(); ?> <h1 class="page-title"><?php the_title(); ?></h1> <aside> <?php echo get_the_post_thumbnail($page->ID, array('400', '300'); ?> </aside> <div class="wraparound"> <?php the_content(); ?> </div><!-- end .wraparound --> <?php else: // 404 message endif; get_footer();
  • 20. Download This x96design.com/other/wcv11 ● All source code for functions.php, single- project.php, and project-list.php. ● My presentation (slides) for reference.