Web Design Forum: Wordpress Different Sidebar on different pages/posts? - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Wordpress Different Sidebar on different pages/posts? How to? Rate Topic: -----

#1 User is online   pbul2004 

  • Expert
  • PipPipPipPip
  • Group: Members
  • Posts: 550
  • Joined: 25-January 10
  • Reputation: 7
  • Gender:Male
  • Location:Warrington
  • Experience:Nothing
  • Area of Expertise:Web Developer

Posted 03 September 2010 - 08:06 AM

I have a CMS website in Wordpress, however for different pages and posts on there i would like to display different sutff on the sidebar depending on what page you are on.

At the moment the same information is displayed in the sidebar for all pages and posts, however i would like it so that different pages/posts have sidebar info relating to that particular page/post?

Anyone know how to do this, or where i would start?

Cheers
Paul
0

#2 User is offline   Lee Boyce 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 136
  • Joined: 31-August 08
  • Reputation: 1
  • Location:Scotland
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 03 September 2010 - 08:26 AM

The best way to do this, that i know of, is to make use of the custom fields.

If you open your single.php page, or post.php page in an editor you will be able to find the line:

<?php get_sidebar(); ?>


You want to be able to edit this so that it can acquire the information needed to display the correct sidebar. So replace with:

<?php $sidebar = get_post_meta($post->ID, "sidebar", true); get_sidebar($sidebar); ?>


Now, to display a custom sidebar in a post or page; add the custom field “sidebar” and include the name of the sidebar file. E.g. if you insert “test”, it will display
sidebar-test.php as your sidebar.

I hope that makes sense, however, i just realised... you will need to have the ability to enable widgets in more than one sidebar. Check out this tutorial on how to do so:
Multiple Sidebars Wordpress
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users