An Introduction to Custom Post Types

766 views
692 views

Published on

Have you ever used a theme or a plugin that offers an additional content area outside of the standard Posts or Pages? These are called Custom Post Types, a great feature in WordPress that allows you to break out into specific areas of content that can be used for anything the mind can imagine.

Whether you are learning about theme development and want to add separate content sections of your own or simply new to using WordPress to manage your content, it is to your advantage to know and understand what custom post types are, and what they can do to simplify your publishing or development life.

This presentation was given at WordCamp Ottawa on April 27th, 2013

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
766
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

An Introduction to Custom Post Types

  1. 1. An Introduction toAn Introduction toCustom PostCustom PostTypesTypesPresented by Troy ChaplinPresented by Troy ChaplinWeb Developer & WordPress EnthusiastWeb Developer & WordPress Enthusiast
  2. 2. A Little About MeA Little About MeGraphic design diploma from StGraphic design diploma from StLawrence College and self taughtLawrence College and self taughtweb developer.web developer.8 year career in print design and8 year career in print design andlayout, marketing, advertising andlayout, marketing, advertising andweb design and development.web design and development.4 years as a web developer at4 years as a web developer atCarleton University designing andCarleton University designing anddeveloping custom CMS’ powereddeveloping custom CMS’ poweredby WordPress and helping maintainby WordPress and helping maintainover 250 WP sites.over 250 WP sites.Loves learning and working withLoves learning and working withWordPress to try and find better andWordPress to try and find better andmore intuitive ways to build custommore intuitive ways to build customfunctionality.functionality.I never code alone.I never code alone.
  3. 3. Sprott School ofSprott School ofBusinessBusiness
  4. 4. Carleton NewsroomCarleton Newsroom
  5. 5. Graduate AdmissionsGraduate Admissions
  6. 6. Carleton AthleticsCarleton Athletics
  7. 7. Carleton HousingCarleton Housing
  8. 8. All those examples useAll those examples usea variety of custom posta variety of custom posttypestypesBut we’ll take a closer look at those laterBut we’ll take a closer look at those later
  9. 9. About Custom PostAbout Custom PostTypesTypesIf you’ve used WordPress, then you may be surprised toIf you’ve used WordPress, then you may be surprised tolearn that you’ve been using custom post types all along.learn that you’ve been using custom post types all along.WordPress uses 5 default post types: posts, pages,WordPress uses 5 default post types: posts, pages,attachments, revisions and nav menus.attachments, revisions and nav menus.Provides the ability to create new content areas andProvides the ability to create new content areas andseparate content on large sites.separate content on large sites.Designers and developers can create layouts andDesigners and developers can create layouts andfunctionality that is separate from posts and pages.functionality that is separate from posts and pages.Used by several plugins to add specific functionality thatUsed by several plugins to add specific functionality thatdoes not impact the default post types.does not impact the default post types.
  10. 10. Its Name Can beIts Name Can beConfusingConfusingCustom post types?Custom post types?Isn’t that the same thingIsn’t that the same thingas the default posts?as the default posts?What’s the difference?What’s the difference?I prefer to think of it as aI prefer to think of it as aCustom Content Type.Custom Content Type.It is tied to none of theIt is tied to none of thedefault post types, actsdefault post types, actsas a stand aloneas a stand alonecontent area.content area.
  11. 11. Custom Post TypeCustom Post TypeFunctionalityFunctionalityCan mirror the familiar functionality of posts: non-Can mirror the familiar functionality of posts: non-hierarchical, categorization, tagging capabilities.hierarchical, categorization, tagging capabilities.Can also reflect the pages environment: pageCan also reflect the pages environment: pageattributes, parent-child relationships.attributes, parent-child relationships.Both can support titles, editors, revisions, customBoth can support titles, editors, revisions, customfields, thumbnails, comments and more.fields, thumbnails, comments and more.Both act and are organized independently from theBoth act and are organized independently from thedefault posts and pages and can be tailored to suit adefault posts and pages and can be tailored to suit avariety of needs across your website.variety of needs across your website.
  12. 12. Sprott School ofSprott School ofBusinessBusinessHomepage slideshowHomepage slideshowand other content areasand other content areasare control with aare control with ahomepage custom posthomepage custom posttype.type.Chronologically sortedChronologically sortedupcoming events list.upcoming events list.Alphabetically sorted listAlphabetically sorted listof faculty and staffof faculty and staffmembers.members.
  13. 13. Carleton NewsroomCarleton NewsroomHomepage featuredHomepage featuredstory and video settings.story and video settings.Default posts as well asDefault posts as well asseveral custom postseveral custom posttypes feeding into thetypes feeding into thehomepage.homepage.In the News is a customIn the News is a custompost type to helppost type to helpseparate internal newsseparate internal newsfrom external news.from external news.Alphabetically sortedAlphabetically sortedexperts at Carletonexperts at Carletonlisting.listing.
  14. 14. Graduate AdmissionsGraduate AdmissionsHomepage slideshow.Homepage slideshow.Alphabetical list ofAlphabetical list ofprograms, split into threeprograms, split into threemain categories.main categories.Chronologically sortedChronologically sortedupcoming events list.upcoming events list.Video gallery.Video gallery.International studentInternational studentrequirements, sortedrequirements, sortedalphabetically byalphabetically bycountry.country.
  15. 15. Carleton AthleticsCarleton AthleticsCampus and kidsCampus and kidsprogram listing.program listing.Fitness class listing.Fitness class listing.Leagues and recreationLeagues and recreationlisting.listing.Pool and facilities listing.Pool and facilities listing.Site wideSite wideadvertisements.advertisements.
  16. 16. Carleton HousingCarleton HousingHomepage with contentHomepage with contentcustomization options.customization options.Alphabetical listing ofAlphabetical listing ofcampus residencecampus residencebuildings.buildings.Video gallery.Video gallery.Off campus housingOff campus housinglistings.listings.Student testimonials.Student testimonials.Promotional highlights.Promotional highlights.
  17. 17. More Ways to Use Custom PostMore Ways to Use Custom PostTypesTypesEntertainment sites: custom post types to separateEntertainment sites: custom post types to separatecontent for movies, television shows, music, books,content for movies, television shows, music, books,games and more.games and more.Sports: custom post types to separate content forSports: custom post types to separate content forhockey, basketball, baseball, football, golf and more.hockey, basketball, baseball, football, golf and more.Online magazines: custom post types to separateOnline magazines: custom post types to separatecontent for editorial section such as features, letters,content for editorial section such as features, letters,shorts, guest columnists and more.shorts, guest columnists and more.
  18. 18. The Basics of theThe Basics of theFunctionFunctionadd_action( init, create_post_type );function create_post_type() {register_post_type( wco_notes,array(labels => array(name => __( WordCamp Notes ),singular_name => __( WordCampNote )),public => true,has_archive => true,));}
  19. 19. Theme FilesTheme FilesCustom post type archives functions similar to theCustom post type archives functions similar to thecategory template using a file namedcategory template using a file named archive-archive-post_type_name.phppost_type_name.phpSingle page function like a post or page and use aSingle page function like a post or page and use atemplate file namedtemplate file named single-post_type_name.phpsingle-post_type_name.phpIf neither of these templates files exist WordPressIf neither of these templates files exist WordPresswould look for archive.php and single.php.would look for archive.php and single.php.Default URL structure uses post_type_name, but canDefault URL structure uses post_type_name, but canbe customized in more detailed function.be customized in more detailed function.Example: http://sitename.ca/post_type_name/.Example: http://sitename.ca/post_type_name/.
  20. 20. Coding TutorialsCoding TutorialsWordPress CodexWordPress Codexhttp://codex.wordpress.org/Function_Reference/regihttp://codex.wordpress.org/Function_Reference/register_post_typester_post_typeJustin TadlockJustin Tadlockhttp://justintadlock.com/archives/2010/04/29/custohttp://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpressm-post-types-in-wordpress
  21. 21. Some Plugins to HelpSome Plugins to HelpCustom Post Type UICustom Post Type UIhttp://wordpress.org/extend/plugins/custom-http://wordpress.org/extend/plugins/custom-post-type-ui/post-type-ui/TypesTypeshttp://wordpress.org/extend/plugins/types/http://wordpress.org/extend/plugins/types/Both plugins allow for quick and easy creation ofBoth plugins allow for quick and easy creation ofcustom post types, as well as taxonomies /custom post types, as well as taxonomies /categoriescategories
  22. 22. Things to RememberThings to RememberUse post types to create unique sections on yourUse post types to create unique sections on yoursite that provide functionality that is different thansite that provide functionality that is different thanthat of default blog posts and pages.that of default blog posts and pages.Use them on large scale site to better organize aUse them on large scale site to better organize avariety of areas of content. Better for writers,variety of areas of content. Better for writers,easier for visitors.easier for visitors.Not comfortable with editing code? Use a plugin!Not comfortable with editing code? Use a plugin!Think outside the box. Nothing is impossible.Think outside the box. Nothing is impossible.
  23. 23. Questions?Questions?
  24. 24. Troy ChaplinTroy Chaplintroychaplin.catroychaplin.ca@troychaplin@troychaplinThank You forThank You forComing!Coming!

×