sidebar in wordpress - wordpress

I want to display different dynamic sidebar on different pages, how do I access multiple sidebar on my pages.

Place some form of hook on different pages.
Open sidebar.php in your themes and check for presence of hook.

You should create files like sidebar-xxxx.php and include it, using get_sidebar(xxxx) in the different templates and souhld register them on the functions.php. If you do not wanna create these files you can register the sidebars on functions.php and in the sidebar.php use:
global $wp_query;
$page_name = $wp_query->post->post_name;
<ul>
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('sidebar-'.$page_name) ) : ?>
<?php endif; ?>
</ul>

create a new sidebar
and you can link them inc with is page
if(is_page(5)) {
include('new-sidebar.php')
}
is page id is 5 lets say thats the id for your home page
just check the ids of your pages and seperate them
if you want them tho show in the page childs to
just write
if(is_page(5) || $post->post_parent) {
include('new-sidebar.php')
}
zou can even write a function either

For different sidebars, i thing you have to do is to create the sidebar which you want as many as you want and save those sidebars as sidebar1.php, sidebar2.php and so on.
And,just include it in the different pages where you want it to display like this:
<?php include('sidebar1.php'); ?>
And, like wise for other sidebars of other pages.

Related

How to differentiate Front page and other pages in Wordpress?

I have created a front page (i.e index.php) with my own design. This page will contain
header got from <?php get_header(); ?> [has navigation bar code]
Then some content. Here I'm showing three thumbnails of posts. [has slider, thumbnail posts etc]
And a footer from <?php get_footer(); ?>[has footer links]
The problem is, I see index.php loaded correctly as a front page. But when I navigate to other pages like About or Contact, the respective content from these pages is not showing up. Instead what getting loaded there is, same what Index page has. I don't want slider or thumbnail appearing on these pages.
So how to tell wp that, this is my front page, and this is my About page, don't load a slider and stuff on About page!?
use is_front_page() to determine the home page. like you only want slider on the home page then edit your header.php file that consist the slider part and do something like this
if( is_front_page() ):
// Front Page stuff like slider and
// whatever you want
endif;
Try this ,
if( is_home() || is_front_page() ){
//your home page content
}
else{
//other pages
}
For more here
Hope its works..
Make another template and set this template for your single pages. And then from backhand set it.
I usually create a front-page.php file, Wordpress will use that instead of index.php (which you can use as a generic template from then on).

wordpress custom pre-fixed templates

I want to create a page template that has a pre-fixed css. Lets say I name it page-sevencol.php then I know that the content will have a fixed width and a specific style and so on. My pages have different layouts thats why I need to create these kind of templates.
Is it possible? if so how? Ive looked in the wp codex and it does not seem to have the answer. Please take a minute to help me.
Thank you!
you seem to need just a limited set of templates. The question is: do you want to apply them automatically? Basically, there are two techniques to apply a template to a page (or post or custom post, etc.) in WordPress.
First method: using the template naming convention to get the template automatically applied to a page (or post) with the same name.
In this case, you create a page page-mynewpage.php and this template will automatically get applied to your page named /mynewpage/.
Second method: you create a template by creating a page (let's say : template1.php) and declaring it as a template with a comment at the top of the page:
/**
* Template Name: Template1
*
*/
This template will now be selectable inside the admin of WordPress to be applied to any page:
So if A) you only need a limited set of templates & B) are ok to select them on a per-page basis in the admin, this is your solution. You would just need to create as many pages as you need templates, not forgetting to include the comments that declare them as templates and using a different name each time.
If you need your templates to be applied dynamically, then we need more info about the logic to use for select each template...
EDIT : That is it, Abel (just read your comment). Your page is mainly generated with 4 elements: header.php, sidebar.php, footer.php and another page to produce the content, but this page is different depending on where you are in the site. If you are on a page, it will be, by default, page.php. If you are reading a post, WordPress will by default use single.php.
To apply all your different templates, just go and open page.php in your theme folder. Save it under another name, like page-template7cols.php. Insert a comment like I just explained above, so this template will show in your admin next time you create a new page. Adapt it the way you want (changing the HTML / PHP and therefore adapting the way the content of the page will be displayed). Do the same for your other 9 templates.
Then, everytime you create a new page, just start by selecting the proper template in your dropdown (see previous screen capture). And whenever you will make a change to page-template7cols.php, for example, the changes will be reflected on all pages for which you have selected this template.
/**
Template Name: Template1
*/
<?php get_header(); ?>
<div class="content-wrap sevencol clearfix">
<div class="row clearfix">
<div class="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<?php endwhile; endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

External sidebars in WordPress

I need to display several sidebars with custom context.
I suppose that I need to add several additional blogs to be displayed as sidebars. That is for every sidebar I am going to create a little specialized blog.
The question: How to make sidebars from a different blog to be displayed in a blog sidebar?
If you want to add more than one sidebar, you need to create sidebar for each blog and name it. E.g., want to create sidebar for aboutus.php (created as template page). Create sidebar as sidebar_aboutus.php and add what you want in sidebar to it.
Then include that sidebar_aboutus.php in your aboutus.php like this:
<?php
/**
* Template Name: About us
*
* Selectable from a dropdown menu on the edit page screen.
*/
?>
<?php get_header(); ?>
<?php include ('sidebar_aboutus.php'); ?>
<?php get_footer(); ?>
Likewise, you can create and include as many sidebars as you need for your different blog pages.

How to remove sidebar from certain pages and adjust post width div?

I'm trying to remove the sidebar from certain pages and once it is removed the width of the post div readjusts. How to do this?
For pages you can create different template and use it with a specific pages. For posts you can use a custom field to mark pages that requires no sidebar, then read this custom field in your single.php and make corresponding layout adjustments. Hope you know how to do it.
You can use the simple PHP script in page.php to remove the sidebar from specific page.. Here is the PHP script-
<?php if (is_page('your_page_name')) { ?>
<? } else { ?>
<?php get_sidebar(); ?>
<? } ?>
Here is the complete tutorial on removing the wordpress sidebar from specific page http://masterblogster.com/how-to-hide-sidebar-on-particular-page-in-wordpress/

include link list depending on category

I want to display the linklist widget only on a certain category.
The current way the sidebar is fetched is:
if (!function_exists('dynamic_sidebar') || !dynamic_sidebar(1))
Which doesnt give me a say in the calling of the links widget. If i put an if clause there, then the rest of the widgets dont get loaded.
So i either need to customize the links widget it self or find a way to call the links widget directly?
And how do i check which category i'm on?
You can call an indivdual widget by using Conditional Tags « WordPress Codex, like this:
<?php if (in_category('1')) { ?> call widget here
<?php } ?>
Or (haven't used this myself) load widgets by category, etc: WordPress › Dynamic Widgets « WordPress Plugins
To print the Category you are on use the_category(' ');
Example :<p>Categories: <?php the_category(' '); ?></p>
Also have a look at the Documentation http://codex.wordpress.org/Template_Tags/the_category

Resources