Can you put categories on select pages and not all of them
-
Hi, Can you add categories to maybe one or two pages, without putting the categories on all of your pages. If so, how can you accomplish this. Is there a plugin or widget?
Thanks,
Dave Fennell
-
There are a lot of ways this could be done, but the easiest would be to use widgetized areas (aka sidebars).
A lot of modern themes come with often times a ridiculous number of widgetized areas. Depending on the client I am working for I will make as many widgetized areas as necessary. But by default I use the following strategy as my starting point…
- Home sidebar
- Blog sidebar
- Pages sidebar
- 3-4 Footer areas
Then I add new areas as needed. But the logic here is that if you are running a website with a blog and not just a blog, probably you are going to want different sidebar content for site pages than in your blog. And moreover most professional sites have a fully custom home page layout so that is definitely going to need it’s own. But in many cases you will have whole sections, individual pages/categories/templates that you want to have it’s own sidebar widget areas.
I use something like this in my sidebar.php to output the above examples…
if ( is_front_page() ) ...dynamic sidebar code here for 'home' sidebar... else if ( is_page() ) ...dynamic sidebar code here for 'page' sidebar... else ...dynamic sidebar code here for 'blog/other' sidebar...
This is the code from TwentyTen to add a new widgetized area…
register_sidebar( array( 'name' => __( 'Primary Widget Area', 'twentyten' ), 'id' => 'primary-widget-area', 'description' => __( 'The primary widget area', 'twentyten' ), 'before_widget' => '<li id="%1$s" class="widget-container %2$s">', 'after_widget' => '</li>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>', ) );
Change
'Primary Widget Area'
,'primary-widget-area'
, and'The primary widget area'
to the new name of the widget area, the id of the widget area (also used to output it – see below), and the text that will appear in the widget box in the admin to describe what/where that widget area is for.The simplest way to output the dynamic sidebar is…
if ( ! dynamic_sidebar( 'id-you-entered-for-new-area' ) ) { }
However you are also going to need to edit your sidebar with some conditions to determine which sidebar should be showing (see my example above). OR you can make a page template and a new sidebar template (e.g. special-pages1.php and sidebar-special-pages1.php or whatever) and include the “special pages” sidebar explicitly in the “special pages” template.
But I’m not sure there is a quick and easy answer if you are not already comfortable with php other than review these codex articles and experimenting/learning…
http://codex.wordpress.org/Function_Reference/register_sidebar
http://codex.wordpress.org/Function_Reference/dynamic_sidebar
http://codex.wordpress.org/Stepping_Into_Templates
http://codex.wordpress.org/Templates
http://codex.wordpress.org/Theme_DevelopmentEverything you need to do this (and more) are in those links.
This is the sort of thing that I have seen plugins for that seem unnecessary when, with a little bit of html/css/php and the codex, it really is only a few lines of code in the right place.
I hope this helps. Find your day well.
Hey what exactly you want to do? You wanted to put list of categories in sidebar of one or two pages?
UPDATE :
Try to find such code in your themes sidebar.php<div class="widget widget_categories"> <h3>Categories</h3> <ul> <?php wp_list_categories(); ?> </ul> </div>
Above code will display a list of categories in sidebar. So you have to add a conditional statement so that the code will execute only in particular pages.
Include above code bewteen this :
if ( is_home(array(42,2,4))) { // put the code which shows the list of categorie here }
( 42,2,4 are page-ID’s on which you want to show list of categories.)
Thats it, it will show the list of categories only on three pages.
- The topic ‘Can you put categories on select pages and not all of them’ is closed to new replies.