Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Add Custom Sidebar to wpfolio WordPress

  • SOLVED

I’d like to know how to add a sidebar or container of some sort to certain pages in WPFolio. I have a child theme, WPFolio-child-theme. I am selling downloadable music and I need the shopping cart to always be visible only on store related pages in the upper right corner of the page (where the first widget would be in a regular sidebar), but not on any other page. My research tells me the way to do this may be a custom page template in my child theme that will have a sidebar text widget that displays the shopping cart, or some sort of “container” only on pages I designate to use that template? I guess if it’s a container it will have to be able to expand, as a widget would, as things are added to the cart. There are so many product pages that a template for each page would be impractical. My eStore plugin has provided shortcode for displaying the shopping cart in a text widget (it looks nice, too). There is also a php function for the shopping cart provided to me by my eStore plugin developer that will display the shopping cart <?php echo wp_digi_cart_always_show(); ?>
As I said, the catch is I’d want to call up that template only for these store pages; and I don’t want the other sidebar widgets (those presently on my home post/page, for instance) to be visible (in fact, the default for WPFolio is sidebar on posts only, the sidebar doesn’t show on pages). I can follow complicated instructions but I’m a composer, not a coder, so instructions like “just stick this in the loop in your index.php” will not be enough.
Or any other old way you smart folks figure is best! Here’s a couple of pages on my site under construction. I’ve temporarily placed the shopping cart in the home page sidebar, using shortcode, in a text widget, solely to give an example of how it looks:
http://blog.themikieshow.org
Here are a couple of music store pages, so far, as examples of where I will want the shopping cart to appear.
http://blog.themikieshow.org/music-store
http://blog.themikieshow.org/category-symphonic
Thanks a bunchy bunch!

Answers (2)

2011-07-11

Duncan O'Neill answers:

Hi,

here's a generic function to register widgetable areas. Put this in your functions.php file in your child theme folder.


// Register widgetized areas
function theme_widgets_init() {
// Area 1
register_sidebar( array (
'name' => 'My New Sidebar',
'id' => 'primary_widget_area',
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );


// Area 2

register_sidebar( array (
'name' => 'Secondary Widget Area',
'id' => 'secondary_widget_area',
'before_widget' => '<li id="%1$s" class="widget-container %2$s">',
'after_widget' => "</li>",
'before_title' => '<h3 class="widget-title">',
'after_title' => '</h3>',
) );
} // end theme_widgets_init


add_action( 'init', 'theme_widgets_init' );


Call it in one of your theme files like this;


if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('My New Sidebar') ) : ?>
// code for if sidebar not called
endif;


Duncan O'Neill comments:

Hi Michael,

here's another ( simpler ) plan, which should put the shopping cart in your sidebar for store pages;

1) back up your files, or make sure you have the originals somewhere.
2) save your index.php from your PARENT theme folder ( wpfolio ) as page.php in your child theme folder.
3) Go to the place in your new page.php in your child theme folder just below where it says <div id="sidebar">, and add this code;


<?php
if (is_page('music-store')){
echo wp_digi_cart_always_show();
}


Please let me know if this works.


Duncan O'Neill comments:

Sorry, that should also have the closing php tag on it;


<?php

if (is_page('music-store')){

echo wp_digi_cart_always_show();

}
?>


Michael Carroll comments:

Okay, so the theme file I would call it in would be a custom page template file? Do I make a copy of my current page template, rename it, then put that in my child theme? If so, how do I assign only certain pages to use that custom template? Plus, the above gentleman says my pages are coded to show full width, I assume your code will amend those instructions to allow for the widget to show. Not doubting, just want to give you all the info necessary. Thanks.


Michael Carroll comments:

This is looking good. I hope I can ask another question. The "music-store" is just one of the pages that need the cart displayed. As folks search for music, a page that defines a certain genre of music will come up. There could be 100 different music store pages. Is there a way to designate a type of page that I can tag every music store related page with, that will call this sidebar widget scenario? My wife says no matter where one is in the store, the cart should always be visible (she's a shopper:)) Thanks.


Duncan O'Neill comments:

Michael,

I was advising you to have a backup copy of your files in case something goes awry, so that you can return to the status quo if necessary.

Then open index.php from your parent theme folder, and SAVE IT AS page.php in your child theme folder. This will give your pages a sidebar. You don't have to do any assigning, the theme will use the page.php for pages.

You can contact me directly at [email protected] if you need to.

best,

Duncan


Duncan O'Neill comments:

Michael,

in answer to your question at 6.32pm;

Yes, you can create a template, and instruct all store pages to use that template like this;

1) Add the following code to the top of your new page.php;
<code>
<?php
/*
Template Name: store
*/
?>

2) Go into your wp-admin. Edit the store page. On the right, probably the second box down will be titled 'Page Attributes'. There is a drop-down showing your available templates. Choose 'store'. Now all your store pages should use this template.

best,

Duncan


Duncan O'Neill comments:

Michael,

Sorry, please ignore that last, I forgot to close a code tag. Here it is again;

in answer to your question at 6.32pm;

Yes, you can create a template, and instruct all store pages to use that template like this;

1) Add the following code to the top of your new page.php;

<?php
/*
Template Name: store
*/
?>


2) Go into your wp-admin. Edit the store page. On the right, probably the second box down will be titled 'Page Attributes'. There is a drop-down showing your available templates. Choose 'store'. Now all your store pages should use this template.

best,

Duncan


Michael Carroll comments:

Okay, this all looks really good.

2011-07-11

Kemal Pince answers:

Hi;

Easy..Get the custom sidebars plug in by Javier Marquez. Also, the exec-php plugin by Sören Weber. Make sure php execution is allowed on widgets (check the plug in settings). Add a new custom sidebar. Use that custom sidebar on pages where you want your cart to appear. In your widgets add a text/free html widget to that sidebar. Place your php code in the widget. That's all.

If you have any questions feel free to ask.

Cheers !


Michael Carroll comments:

Hi there. Sorry, but this doesn't work. First off there's a warning coming up on my page edit that refers to menu options in my profile that don't exist. Perhaps this was taken out for WP 3.2? The plugin says it has not been tested on my version. Regardless, that warning seems to be about ruining php code in the body of an article, which there is none in my pages. So I tried to configure the extra sidebar, default sidebar, custom sidebar, etc, etc. I went to widgets, added the text widget with the php code to the custom sidebar, added the custom sidebar to a page, but it never shows up. After three attempts, I give up. Frankly, the whole custom sidebars menu under appearance was confusing. Maybe this is because wpfolio is hardcoded for no sidebars on pages?


Kemal Pince comments:

Hi;

What version of wordpress are you running ? I'm not familiar with WPFolio, just checked it and it's a free theme. It's probably an outdated theme in which case you'll run into problems using plugins that have been recently updated (i.e. ones that will only work with recent versions of wordpress).

Please don't get me wrong but if you're doing anything that's even slightly commercial (which you seem to intend) using free themes is not a good idea. They'll only get you so far. I would use the latest version of wordpress (it will always save you time and headaches to do so) and spend a few bucks (35 max) on a decent theme with good support (try themeforest.net). How much is your time worth per hour ?

KP


Michael Carroll comments:

I'm using WP 3.2 the newest version and the WPFolio theme has just been updates in the last few days.


Kemal Pince comments:

Hi;

Let me try the theme..Give me a few minutes..


Kemal Pince comments:

Hi;

The theme shows sidebars on posts only and the pages are configured to display full width with no sidebar. You'll need to add the necessary code to display sidebars on pages to page.php and also change the page template so it will not allocate the full width to content and leave space for the sidebar.

I tried the plugins on posts on a custom sidebar and it works.

I still suggest you get a commercial theme not just for sidebar support on pages but also for the looks as you'll need it for your project. Why not try the plugins on the default twentyeleven theme to see how it works ?

If you still want to change the code, you'll have to ask someone else as I'm sure there are better experts on it. At least you know how to proceed from here (I hope).

KP