Saturday, September 8, 2012

How to Adding Sidebar on WordPress Blog


Adding Sidebar In WordPress Blog. Learning php tu indeed easy bother. Make sure tu dizziness, nausea, sometimes vomiting until ... haha ​​.. but for the painstaking, diligent explore, learn and play scripts and coding-coding every day to be exciting. There modif modif here, try and point of satisfaction after the error-coding coding modifanya goes according to plan. It was a relief .. Just like me. When the code that we want to put ga successful, curious even arise. There browsing browsing here, just have to see. ga see you now, be continued tomorrow. As it is also possible that longer read this .. hehe.

Code For Adding Sidebar
Ok.. lets get started!

well, we got into the discussion. This time I want to share tricks on how to add a sidebar on your wordpress blog.
The first step is to register the sidebar that we will create in the functions.php file. Insert this script in the file functions.php. script below work raises sidebar option when you want to install the widget.

[php] <? php
if (function_exists ('register_sidebars'))
register_sidebars (2);
?> [/ php]

Figures (2) above indicates that there are 2 pieces of sidebar. To add to write (3) or how many will be filled up. Then click "update file". After that now we create the file aspects. Create the directory via cpanel / public_html / wp-content / themes / namatheme by clicking the new file. Name the file with the extension. Php, eg sidebar_anyar.php. Then the contents of the file with the following code:

[php] <div>
<ul>
<? php if (function_exists ('dynamic_sidebar') && dynamic_sidebar (3)): else:?>
<? php endif;?>
</ ul> </ div> [/ php]

Adjust the numbers (3) the amount of the sidebar you will make. Save the job.
Well after that we stayed edit template files such as index.php, single.php, page.php or any file that we will come up with the sidebar. Add this code to call the new sidebar file.

[php] <? php include (TEMPLATEPATH. '/ sidebar_baru.php');?> [/ php]

Sometimes there is a different template file contents function.phpnya. For example, like this:

[php] <? php
if (function_exists ('register_sidebar'))
register_sidebar (array (
'name' => 'sidebar-1',
'before_widget' => ',
'after_widget' => ',
'before_title' => '<h2>',
'after_title' => '</ h2>',
));
?> [/ php]

If you like these themes usually has only one sidebar.php file containing multiple sidebar. Actually, we can change the functions.php file to be like the previous one but more hassle of having to split the sidebar file becoming fragmented. Should we just edit the functions.php file. Copypaste sidebar code that is underneath it looks like:

[php] <? php
if (function_exists ('register_sidebar'))
register_sidebar (array (
'name' => 'Sidebar-1',
'before_widget' => ',
'after_widget' => ',
'before_title' => '<h2>',
'after_title' => '</ h2>',
));
if (function_exists ('register_sidebar'))
register_sidebar (array (
'name' => 'Sidebar-2',
'before_widget' => ',
'after_widget' => ',
'before_title' => '<h2>',
'after_title' => '</ h2>',
));
?> [/ php]

Do not forget to rename sidebarnya (the color red), click the update file or save. Well now we open the sidebar.php file. If previously we've put a widget on the sidebar long it will be widely available widget code. But more than the contents of the main code is like this:

[php]
<div class="sidebar-1">
<ul>
<? php if (! function_exists ('dynamic_sidebar') | |! dynamic_sidebar ('sidebar-1')):?>
<? php endif;?>
</ ul>
</ div>
<- / sidebar-1 ->
[/ php]

stay copypaste the code below and change the name of the old sidebar sidebarnya, it looks like:

[php] <div class="sidebar-1">
<ul>
<? php if (! function_exists ('dynamic_sidebar') | |! dynamic_sidebar ('sidebar-1')):?>
<? php endif;?>
</ ul>
</ div>
<- / sidebar-1 ->

<div class="sidebar-2">
<ul>
<? php if (! function_exists ('dynamic_sidebar') | |! dynamic_sidebar ('sidebar-2 ")):?>
<? php endif;?>
</ ul>
</ div>
<- / sidebar-2 -> [/ php]

Nb: replace single quotation marks (') and quotes two (") in the above code
Update the file or save, done. to set the width and the effects on the sidebar edit style.css file. Do not forget to add the new sidebar code we get there, how easy it is to copy and paste the code wrote and rename the old sidebar. Well now simply add the widget on the sidebar through the Appearance menu - widgets

No comments:

Post a Comment