Start Online Training

Get access to all our video classes and support. That's 1818 training sessions in Joomla, Drupal, WordPress, Coding and SEO.
Prices start only at only 25 USD per month

Testimonials

Testimonials OSTrainingThanks for the great training! I'm normally more inclined to be a visual than a coder, and these videos have began removing the wall of fear that has kept me from learning coding. Working with WordPress got me interested, and I'm so glad I found you all! "

~ Caleb Walker

 

Start a FREE 7 day trial! Get training videos and books, plus expert support:  

TOPIC: Creating custom sidebars using hooks

Creating custom sidebars using hooks 1 year 2 months ago #64468

Hi,

I am working on a starter theme that has all content hooks defined.

Unlike startbox that auto generates shortcodes for sidebars when appropriate parameter are defind, This theme does not.

I was therefore wondering if there Is any way of executing a function on a hook spot, given this scenario?
Any leads would be appreciated.

This is my function statement:

function vweb_homepage_widget (){
print do_shortcode(‘[]‘);
}
add_action( ‘basestation_main_before’,'vweb_homepage_widget’ );

Thanks.
Please become a member of OSTraining to reply to this post.

Creating custom sidebars using hooks 1 year 2 months ago #64507

  • steve
  • steve's Avatar
  • OFFLINE
  • Posts: 5921
  • Thank you received: 262
Hi terungwa

OK, that generates a couple of questions from me:

1) Which starter theme are you using?
2) Is your main goal to put a shortcode inside a widget, or is that just an example function?
Ask. We'll help. It's as simple as that.

Follow us on Twitter - twitter.com/ostraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

Creating custom sidebars using hooks 1 year 2 months ago #64634

Hi Steve,

I am using Base Station a responsive starter theme, built with the Zurb Foundation framework.
What I wish to achieve is to:
  1. Run a shortcode ,
  2. using the hook spot,
  3. to create a custom sidebar at the identified hook spot.

So, without shortcodes that startbox provides, is there a way of approaching this?

Thanks.
Please become a member of OSTraining to reply to this post.

Creating custom sidebars using hooks 1 year 2 months ago #64760

  • steve
  • steve's Avatar
  • OFFLINE
  • Posts: 5921
  • Thank you received: 262
Hi terungwa

One caveat before I go any further: custom code is beyond the scope of our support: www.ostraining.com/support-forum/faq/

However, let me help as well as I can here.

I believe that feature is custom to Startbox. They've got unique functions do just that: wpstartbox.com/2011/08/21/sidebar-registration/

Would it make more sense in this case to do everything through functions or is that missing a functionality that you need? www.tastyplacement.com/add-sidebar-wordpress
Ask. We'll help. It's as simple as that.

Follow us on Twitter - twitter.com/ostraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

Creating custom sidebars using hooks 1 year 2 months ago #64765

Thanks Steve,

This lead is all I needed!
Please become a member of OSTraining to reply to this post.

Creating custom sidebars using hooks 1 year 2 months ago #64766

I wish to add though, that my aim of asking the question was not necessarily to obtain a custom code solution. But as a student of wordpress, I just feel, I should be in a position to resolve issues that do not come out of the box such as this! And that is why we have learned instructors who may not necessarily provide cooked answers but point out how we may go about resolving design issues such as this.

Thanks for the link. It is just what i needed.
Please become a member of OSTraining to reply to this post.

Creating custom sidebars using hooks 1 year 2 months ago #64767

  • steve
  • steve's Avatar
  • OFFLINE
  • Posts: 5921
  • Thank you received: 262
You're welcome, terungwa.

Sorry I wasn't clearer. We get a few people who want to us write themes or plugins for them, so we just add that disclaimer out of habit.

I'm glad the link helped. Let me know if you get stuck while trying to implement it.
Ask. We'll help. It's as simple as that.

Follow us on Twitter - twitter.com/ostraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

Creating custom sidebars using hooks 1 year 2 months ago #64791

Hi Steve,
I have created my sidebar and its sure looking great! but one challenge though, the conditional tag if(is_front_page()) does not seem to be working in term of displaying the sidebar on the front page only. the sidebar is appearing on all pages.

I had to switch to the twenty twelve theme to confirm, but it is still appearing on all pages.

Any advice is appreciated.

Thanks.
Please become a member of OSTraining to reply to this post.

Creating custom sidebars using hooks 1 year 2 months ago #64824

  • steve
  • steve's Avatar
  • OFFLINE
  • Posts: 5921
  • Thank you received: 262
Hi terungwa

Could you post your code here? I'll take a look for you.

Also, what are you using for your site's homepage? Posts? A page? Something else?
Ask. We'll help. It's as simple as that.

Follow us on Twitter - twitter.com/ostraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

Creating custom sidebars using hooks 1 year 2 months ago #64881

Hi Steve,
I am using a static page for the homepage.
This is the code for the sidebar.homepage.php file:
<div id="sidebar">
<ul>
<?php
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('homepage-sidebar') ) :
endif; ?>
</ul>
</div>

This function inserted the sidebar at the hook-spot i chose:
<?php do_action( 'alienship_main_before' ); ?>
<?php get_sidebar('homepage'); ?>

I included the conditional tag here to display only on front page, but still showing on all pages:
if (is_front_page()){ <?php get_sidebar('homepage'); ?>}

I also tried this as well:
if (is_front_page()){if ( function_exists('register_sidebar') ) {
register_sidebar(array(
'name' => 'Homepage Sidebar',
'id' => 'homepage-sidebar',
'description' => 'Appears as the sidebar on the custom homepage',
'before_widget' => '<div style="height: 280px"></div><li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
));
}}

Thank you.
Please become a member of OSTraining to reply to this post.

Creating custom sidebars using hooks 1 year 2 months ago #64949

  • steve
  • steve's Avatar
  • OFFLINE
  • Posts: 5921
  • Thank you received: 262
Hi terungwa

This will very much depend on your answer to the question, what are you using for your site's homepage? Posts? A page? Something else?

But, this should work for most cases:
<?php if(is_front_page()): ?>
 
Your code
 
<?php endif; ?>
Ask. We'll help. It's as simple as that.

Follow us on Twitter - twitter.com/ostraining
Like us on Facebook - facebook.com/ostraining
Please become a member of OSTraining to reply to this post.

 

Start a FREE 7 day trial! Get training videos and books, plus expert support: