{"id":30074,"date":"2010-04-07T16:27:14","date_gmt":"2010-04-07T20:27:14","guid":{"rendered":"http:\/\/wpmu.org\/?p=30074"},"modified":"2012-10-02T23:03:01","modified_gmt":"2012-10-03T03:03:01","slug":"daily-tip-select-sidebar-on-a-post-by-post-basis-using-custom-fields","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/daily-tip-select-sidebar-on-a-post-by-post-basis-using-custom-fields\/","title":{"rendered":"Select Sidebar on a Post-by-Post Basis Using Custom Fields"},"content":{"rendered":"<p>If you&#8217;ve ever wanted to use different sidebars for different post categories or even individual posts, here&#8217;s a quick and easy way to put a little more customization into your templates.<\/p>\n<p>Open your <i>single.php<\/i> file and locate the sidebar:<\/p>\n<p><code>&lt; ?php get_sidebar(); ?&gt;<\/code><\/p>\n<p>Replace it with this:<\/p>\n<pre>&lt;?php $sidebar = get_post_meta($post-&gt;ID, \"sidebar\", true);\r\nget_sidebar($sidebar);\r\n?&gt;<\/pre>\n<p>Now when you want to use a different sidebar, you&#8217;ll simply create a custom field called &#8220;sidebar.&#8221; Give it the value of the custom sidebar templates you&#8217;ve created- for example: <i>sidebar-news.php, sidebar-full.php, sidebar-photos.php<\/i>.\u00a0If you want to use your news sidebar, give the custom field the name &#8220;sidebar&#8221; and the value &#8220;sidebar-news&#8221;.<\/p>\n<p style=\"font-size: 11px;\"><a href=\"http:\/\/spyrestudios.com\/10-wordpress-hacks\/\" rel=\"noopener\" target=\"_blank\">Source: SpryeStudios.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve ever wanted to use different sidebars for different post categories or even individual posts, here&#8217;s a quick and easy way to put a little more customization into your templates. Open your single.php file and locate the sidebar: &lt; ?php get_sidebar(); ?&gt; Replace it with this: &lt;?php $sidebar = get_post_meta($post-&gt;ID, &#8220;sidebar&#8221;, true); get_sidebar($sidebar); ?&gt; [&hellip;]<\/p>\n","protected":false},"author":4099,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[1,263],"tags":[4279],"tutorials_categories":[],"class_list":["post-30074","post","type-post","status-publish","format-standard","hentry","category-news-community","category-tutorials","tag-sidebars"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/30074","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/4099"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=30074"}],"version-history":[{"count":3,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/30074\/revisions"}],"predecessor-version":[{"id":181670,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/30074\/revisions\/181670"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=30074"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=30074"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=30074"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=30074"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}