{"id":6368,"date":"2016-02-22T13:15:03","date_gmt":"2016-02-22T18:15:03","guid":{"rendered":"https:\/\/themespress.ca\/?p=6368"},"modified":"2022-09-11T10:56:47","modified_gmt":"2022-09-11T14:56:47","slug":"add-an-image-post-type-columns-in-the-admin","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/add-an-image-post-type-columns-in-the-admin\/","title":{"rendered":"Add an Image Post Type Columns in the Admin"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>With this tutorial, we will show you how to add a column for your post&#8217;s thumbnail and display it in your Admin post type.<\/p>\n<p>Let&#8217;s say our post type is called <strong>viavideos<\/strong>. We will add a new filter to create the column for the image.<\/p>\n<p>In our filter manage_<strong>viavideos<\/strong>_posts_columns, you&#8217;ll notice that you need your post type. It is vital that your post type is specified so it can be executed properly.<\/p>\n<p><strong>Then we build our function:<\/strong><\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-7401867\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-7401867\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">add_filter(&#039;manage_viavideos_posts_columns&#039;, &#039;via_videos_columns&#039;, 5);\nfunction via_videos_columns($defaults){\n    $defaults[&#039;via_videos_post_thumbs&#039;] = __(&#039;Image&#039;);\n    return $defaults;\n}\n<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Then we build the action. We need to fetch the <strong>via_videos_post_thumbs<\/strong> data where our <strong>the_post_thumbnail<\/strong> will be displayed.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Add an Image Post Type Columns in the Admin<\/h2><div id=\"ts-enlighterjs-container-5957551\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-5957551\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">add_action(&#039;manage_viavideos_posts_custom_column&#039;, &#039;posts_via_videos_columns&#039;, 5, 2);\nfunction posts_via_videos_columns($column_name, $id){\n        if($column_name === &#039;via_videos_post_thumbs&#039;){\n        echo the_post_thumbnail( array(50,50), true);\n    }\n}<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>The condition to display is if the name of the column === via_videos_post_thumbs, so it displays <strong>post_thumbnail<\/strong>.<\/p>\n<p>Note that the function includes a width = 50 and height = 50. You can also call the post_thumbnail this way: <strong>echo the_post_thumbnail(&#8216;thumbnail&#8217;);<\/strong><\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"With this tutorial, we will show you how to add a column for your post's thumbnail and display it in your Admin post type. Let's say our post type is<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/add-an-image-post-type-columns-in-the-admin\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4506,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[318,326],"class_list":["post-6368","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-functions","tag-users"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=6368"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6368\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4506"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}