Advertisement
pusatdata

WP-Trik: Display Different Sidebar for Each Post and Page

Oct 14th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. You will need to open your single.php and/or page.php and find the following code:
  2. <?php get_sidebar(); ?>
  3.  
  4. Replace the above code with this:
  5. <?php $sidebar = get_post_meta($post->ID, "sidebar", true);
  6. get_sidebar($sidebar);
  7. ?>
  8.  
  9.  
  10.  
  11. Now when you are writing a post or a page, and you want to display a custom sidebar all you need to do is add the custom field “Sidebar” and include the name of the sidebar file. For example if you insert “wpbpage”, it will display sidebar-wpbpage.php as your sidebar.
  12. Custom Field for Specific Sidebar for Each Page or Post
  13. You must have the file already in place to call it from a specific post. This trick is mostly used in larger magazine style sites, but it is commonly used for custom pages also. One of the easiest way to start out creating a new sidebar file is copying your sidebar.php codes into this new file and edit/add the codes that you want.
  14. We will be covering a few more sidebar hacks, so stay updated if you want to know more about WordPress Sidebars.
  15.  
  16. Sumber: http://www.wpbeginner.com/wp-themes/display-different-sidebar-for-each-post-and-page-for-wordpress/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement