{"id":117119,"date":"2013-04-04T23:13:07","date_gmt":"2013-04-04T23:13:07","guid":{"rendered":"http:\/\/wpml.org\/?p=117119"},"modified":"2018-04-03T12:17:23","modified_gmt":"2018-04-03T12:17:23","slug":"easier-content-management-with-custom-post-types","status":"publish","type":"post","link":"https:\/\/wpml.org\/ja\/tutorials\/2013\/04\/easier-content-management-with-custom-post-types\/","title":{"rendered":"Easier Content Management with Custom Post Types"},"content":{"rendered":"<p><strong>Our list of <a href=\"https:\/\/wpml.org\/contractors\/\">paid contractors<\/a> is growing and we&#8217;ve decided to organize it by language. This means you&#8217;ll be able to find contractors who can help you in your own language. Turns out, custom post types was the right solution for this. Read on to see why.<\/strong><\/p>\n<p>Our contractors page contains a few opening sentences, the list of contractors and a few closing sentences.<\/p>\n<figure id=\"attachment_117140\" aria-describedby=\"caption-attachment-117140\" style=\"width: 162px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/wpml-contractors-areas-cut.png\"><img decoding=\"async\" class=\"size-medium wp-image-117140\" title=\"wpml-contractors-areas-cut\" src=\"http:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/wpml-contractors-areas-cut-162x300.png\" alt=\"\" width=\"162\" height=\"300\" srcset=\"https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/wpml-contractors-areas-cut-162x300.png 162w, https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/wpml-contractors-areas-cut-81x150.png 81w\" sizes=\"(max-width: 162px) 100vw, 162px\" \/><\/a><figcaption id=\"caption-attachment-117140\" class=\"wp-caption-text\">English contractors page<\/figcaption><\/figure>\n<p>We want to have the same structure for the contractor pages, just with contractors who speak each of the languages. For example, here&#8217;s the Japanese page:<\/p>\n<figure id=\"attachment_117127\" aria-describedby=\"caption-attachment-117127\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/wpml-contractors-areas-ja.png\"><img decoding=\"async\" class=\"size-medium wp-image-117127 \" title=\"wpml-contractors-areas-ja\" src=\"http:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/wpml-contractors-areas-ja-300x282.png\" alt=\"\" width=\"300\" height=\"282\" srcset=\"https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/wpml-contractors-areas-ja-300x282.png 300w, https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/wpml-contractors-areas-ja-150x141.png 150w, https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/wpml-contractors-areas-ja.png 745w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-117127\" class=\"wp-caption-text\">Japanese contractors page<\/figcaption><\/figure>\n<p>It&#8217;s built the same way, but with different content.<\/p>\n<p>One way to build these pages would be with regular WordPress pages. That&#8217;s what we had until just yesterday. When the contractors listing started, it listed only two people, so managing it as a regular page was easy.<\/p>\n<p>Today, that page includes 8 contractors and it&#8217;s available in 5 languages, so maintaining it as pages becomes a serious headache. Because we want each of the translated contractor pages to include only certain contractors (who speak that language), we can&#8217;t just send the English page to translation. If we were to use regular WordPress pages, we&#8217;d have to explain to our translators which contractors to include in each language. That&#8217;s a lot of communication and manual work.<\/p>\n<h2>Using Custom Post Types and Fields to Build the List<\/h2>\n<p>So, we moved from regular pages to custom post types and fields. To setup the new custom types, we used our <a href=\"https:\/\/toolset.com\/home\/types-manage-post-types-taxonomy-and-custom-fields\/\">Types<\/a> plugin.<\/p>\n<p>First, we created a new &#8216;contractors&#8217; post type. Then, we added the image, website URL, portfolio and contact fields. Here is how a contractor page looks like in our WordPress admin:<\/p>\n<figure id=\"attachment_117133\" aria-describedby=\"caption-attachment-117133\" style=\"width: 269px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/mana-edit-page.png\"><img decoding=\"async\" class=\"size-medium wp-image-117133\" title=\"Edit page for a contractor\" src=\"http:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/mana-edit-page-269x300.png\" alt=\"\" width=\"269\" height=\"300\" srcset=\"https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/mana-edit-page-269x300.png 269w, https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/mana-edit-page-134x150.png 134w, https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/mana-edit-page.png 900w\" sizes=\"(max-width: 269px) 100vw, 269px\" \/><\/a><figcaption id=\"caption-attachment-117133\" class=\"wp-caption-text\">Edit page for a contractor, using a custom post type<\/figcaption><\/figure>\n<p>Isn&#8217;t this nice?<\/p>\n<p>We have a separate field for every piece of information. When we add new contractors, we don&#8217;t worry about how it&#8217;s displayed on the site. All we need to do is enter the fields. A template will display it properly, along with the other contractors.<\/p>\n<p>Look at the right hand side of the page, where the translation controls are. You&#8217;ll immediately notice that Mana&#8217;s page is available also in Japanese. That&#8217;s the huge benefit that we were looking for. When content is split into small elements, we can easily translate different entries into different languages.<\/p>\n<h2>Displaying the Contractors Lists for Each Language<\/h2>\n<p>Now that we have contractor entries per language, we need to display them.<\/p>\n<p>If you prefer to hack it with PHP, you are more than welcome to use <a href=\"https:\/\/toolset.com\/documentation\/customizing-sites-using-php\/\">Types PHP API<\/a>. When I started to change the contractors page, it was already 10pm and I wanted to finish everything the date changes (and the wife gets upset with me on the PC). I used our <a href=\"https:\/\/toolset.com\/home\/views-create-elegant-displays-for-your-content\/\">Views<\/a> plugin to build the contractors listing, finished the job around 11pm and still had spare hour before my curfew kicks in \ud83d\ude42<\/p>\n<p>The new contractor page uses a template to display each entry. The template looks like this:<\/p>\n<figure id=\"attachment_117136\" aria-describedby=\"caption-attachment-117136\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/profile-elements.png\"><img decoding=\"async\" class=\"size-medium wp-image-117136\" title=\"profile-elements\" src=\"http:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/profile-elements-300x97.png\" alt=\"\" width=\"300\" height=\"97\" srcset=\"https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/profile-elements-300x97.png 300w, https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/profile-elements-150x48.png 150w, https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/profile-elements.png 743w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-117136\" class=\"wp-caption-text\">Template for contractor with different fields<\/figcaption><\/figure>\n<p>I built it using a <a href=\"https:\/\/toolset.com\/documentation\/user-guides\/view-templates\/\">View Template<\/a>\u00a0from within the WordPress admin. A View Template lets me insert fields from the GUI and style them with HTML and CSS. It&#8217;s like writing a standard page, just with field shortcodes instead of static text.<\/p>\n<p>Then, I created a <a href=\"https:\/\/toolset.com\/documentation\/user-guides\/views\/\">View<\/a> to load the list of contractors and display it. When you create a View, you tell it what content type to load, how to filter (in our case, no filtering is needed) and how to display. We&#8217;ve already created a template for a single contractor, so the View just needs to use that template in the listing page.<\/p>\n<p>Here is the contractors page, showing the static content above and below the list and the shortcode to the View showing the contractors list itself.<\/p>\n<figure id=\"attachment_117137\" aria-describedby=\"caption-attachment-117137\" style=\"width: 300px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/contractors-edit-page.png\"><img decoding=\"async\" class=\"size-medium wp-image-117137\" title=\"Contractors listing page\" src=\"http:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/contractors-edit-page-300x225.png\" alt=\"\" width=\"300\" height=\"225\" srcset=\"https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/contractors-edit-page-300x225.png 300w, https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/contractors-edit-page-150x112.png 150w, https:\/\/wpml.org\/wp-content\/uploads\/2013\/04\/contractors-edit-page.png 878w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-117137\" class=\"wp-caption-text\">Contractors listing page<\/figcaption><\/figure>\n<h2>Displaying the Right Content Per Language<\/h2>\n<p>When you use Views to display content in multilingual sites, the language selection happens automatically. This means that when you insert the listing View into an English page, you&#8217;ll get the contractor entries in English. When you insert it into a Japanese page, you get only the entries that are translated to Japanese.<\/p>\n<p>Now, to get certain contractors to appear in other languages, we only need to translate their entries. The View will load the right entries from the database and display on the page.<\/p>\n<h2>Summary<\/h2>\n<p>I started this post about how to make content management easier using custom post types and then it kinda became a mini tutorial for our Views plugin.<\/p>\n<p>The important thing to take here is that for any listing page, custom post types are the way to go.<\/p>\n<p>If you love coding, you can use the WordPress themes API to create custom templates for your content. We love coding too, but I&#8217;m a bit short on time, so I use our Views plugin. <a href=\"https:\/\/toolset.com\/home\/views-create-elegant-displays-for-your-content\/\">Views<\/a> alone costs $95 or you can buy it as part of our <a href=\"https:\/\/toolset.com\/buy\/\">Toolset package<\/a> for $149.<\/p>\n<p><strong>What do you think? How do you build listing pages?<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Our list of paid contractors is growing and we&#8217;ve decided to organize it by language. This means you&#038;#82 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"ep_exclude_from_search":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-117119","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/wpml.org\/ja\/wp-json\/wp\/v2\/posts\/117119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpml.org\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpml.org\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpml.org\/ja\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/wpml.org\/ja\/wp-json\/wp\/v2\/comments?post=117119"}],"version-history":[{"count":8,"href":"https:\/\/wpml.org\/ja\/wp-json\/wp\/v2\/posts\/117119\/revisions"}],"predecessor-version":[{"id":1563330,"href":"https:\/\/wpml.org\/ja\/wp-json\/wp\/v2\/posts\/117119\/revisions\/1563330"}],"wp:attachment":[{"href":"https:\/\/wpml.org\/ja\/wp-json\/wp\/v2\/media?parent=117119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpml.org\/ja\/wp-json\/wp\/v2\/categories?post=117119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpml.org\/ja\/wp-json\/wp\/v2\/tags?post=117119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}