Community Forums › Forums › Archived Forums › Design Tips and Tricks › Simple Sidebar as Secondary Sidebar – How to display it
Tagged: genesis simple sidebar
- This topic has 7 replies, 2 voices, and was last updated 10 years, 8 months ago by
saxisme.
-
AuthorPosts
-
June 5, 2014 at 8:46 pm #108272
saxisme
MemberHello everyone,
I am using Simple Sidebar widget to create custom sidebars.
The on the page I set the newly created sidebar as Secondary Page (Sidebar Selection menu in WP in single Page view).Everything works fine except I see the "empty sidebar" text for the pages where the Secondary Sidebar is not selected with the default text:
Secondary Sidebar Widget Area This is the Secondary Sidebar Widget Area. You can add content to this area by visiting your Widgets Panel and adding new widgets to this area.
Does anyone know how I can programmatically display the sidebar only if it has widgets?
I tried the function
is_active_sidebar
but with no results.This is the code with the conditional statement commented out:
add_action( 'genesis_after_content', 'sax_secondary_sidebar' ); function sax_secondary_sidebar() { //if ( is_active_sidebar( 'genesis_sidebar_alt' ) ) { echo '<div class="clearfix"></div><aside class="after-content widget-area"><div class="wrap">'; do_action( 'genesis_sidebar_alt' ); //it works for all pages, even when the Secondary Sidebar is not defined echo '</div></aside>'; //} }
Can anyone drive me into the right direction? Hints?
Thanks in advance.June 6, 2014 at 5:15 am #108294Brad Dalton
ParticipantYou're referring to 2 different things:
Simple sidebars plugin
And hand coding custom widgets.
Happy to help but please clarify.
Also, where did you get that code from because you generally wouldn't use do_action in a child theme so it looks like a hook from Genesis.
June 6, 2014 at 8:10 am #108308saxisme
MemberHello @braddalton,
Thanks for the reply.
I understand I made a mix of things 😉 This is what I am trying to achieve:
- I want to use a widget area to display some content beneath the main content area
- The content is on per page/category base - this is why Simple Sidebars is envolved. I cannot hard code the sidebar to the page since I don't know its name/ID
- I am using the Sidebar Selection Menu to assign the widget area created with SS, so I wrote the function above to force-display it taking advantage of the Secondary Sidebar option.Of course the problem appears when I don't assign any secondary sidebar, and so the default message empty-widget area pops in. This is what I am trying to avoid.
I made up the code from what I've found in Studio Press and looking at the core files (and playing around a bit).
So the question could be: is there a way to assign a Widget Area created with SS in a Page without hardcoding it?
A custom field on the page with the name of the sidebar I create? Something more end-user-friendly?A big thanks again
June 6, 2014 at 10:04 am #108324Brad Dalton
ParticipantSimple sidebars doesn't enable you to add them after the content. You'll need code for that with conditional tags.
So its unique content after each post?
Or you can use custom fields which is very easy.
June 6, 2014 at 12:55 pm #108359saxisme
MemberHi @braddalton,
yes, that's why I ended up with that code.
Yes, mostly unique content.The logic behind a widgetized area is what I need - drag and drop, and the flexibility of widgets - otherwise I would have to make a lot of shortcodes...
I cannot think of how I could implement the use of custom fields in this scenario.
Thanks,
June 6, 2014 at 1:00 pm #108361Brad Dalton
ParticipantYou can't use a widget if you want it to be unique content after every single post otherwise you will have am enormous amount of widgets or am i off track?
If you want unique content after every post you'll need to use custom fields.
Let me know.
June 6, 2014 at 1:09 pm #108364saxisme
MemberHmmm...
i don't know, surely I will have some widgets, but I find this logic the same as Studio Press uses: use widgets to create a layout.
I don't think a will have a huge amount of widgets, this is an example:
- Homepage - SS Widget Area for: Text Widget A (call to action) + Featured Posts + Genesis Responsive Slider
- About Us - SS Widget Area for: Text Widget B (call to action) + Text Widget C (download brochure) + Genesis Responsive Slider
- Mission - Text Widget B (call to action) + Genesis Responsive Slider
...and so on.And use the SS feature to assign a sidebar to a category for post pages with the same concept above.
I think at the end I would have around 7/10 widget areas + the default Genesis ones.If the client tomorrow wants to add another CTA or change the text, he just changes the widgets in that widget area.
Do you think this schema is not efficient?Thanks,
June 6, 2014 at 1:38 pm #108368saxisme
MemberOk, I have resolved using a custom field with the slug name of the sidebar created with Simple Sidebar and inserting it via this code in functions.php where
wpcf-widget-after-content
is the name of the custom field used./** * Insert custom sidebar created with Simple Sidebar plugin: use as widegtized area after the content * * @author Sacha Benda */ add_action( 'genesis_after_content', 'sax_secondary_sidebar' ); function sax_secondary_sidebar() { $sidebar = get_post_meta( get_the_ID(), 'wpcf-widget-after-content', true); if ( is_active_sidebar ( $sidebar ) ) { echo '<div class="clearfix"></div><aside class="after-content widget-area"><div class="wrap">'; dynamic_sidebar($sidebar); echo '</div></aside>'; } }
Thanks,
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.