Community Forums › Forums › Archived Forums › Design Tips and Tricks › Widget styling (visibility) customisation using conditionals
- This topic has 3 replies, 2 voices, and was last updated 10 years, 9 months ago by
Tom.
-
AuthorPosts
-
April 23, 2014 at 5:30 pm #102111
Robodashy
MemberHi helpfull forum community!
I have included a widget area at the bottom of certain pages to include the "Genesis - Featured Posts" widget, selecting featured posts specific to that page's category and displaying these at the bottom.
I'm wondering if there is a way to have that widget area show up only if there are news items within that category. I would assume it's an if statement or something of the like:add_action( 'genesis_before', 'do_awesome_stuff' );
function do_awesome_stuff {
if (get_category('blah')->category_count > 0) {
// do stuff which removes widget area ... which is where I'm stuck
remove_action( 'something_goes_here' );
}
}I think the reason I'm stuck is because these widget areas have all been added through the Extender Custom settings of the "Genesis Extender Plugin" (awesome plugin) - so I'm not sure how to call in that certain widget.
Am I on the right track? Or way off?
Any help would be greatly appreciated.
The large print giveth, and the small print taketh away.
– Tom Waits, “Step Right Up”May 1, 2014 at 8:17 pm #103266Tom
ParticipantSome of us are familiar with Extender (and some more than others! 🙂 ) but I expect you'll find better expertise over in the forums at CobaltApps. You might also look at the Widget Logic plugin, which allows you to run custom PHP from within any given widget.
Choose your next site design from over 350 Genesis themes.
[ Follow me: Twitter ] [ Follow Themes: Twitter ] [ My Favourite Webhost ]May 1, 2014 at 8:23 pm #103267Robodashy
MemberHi Tom.
Oops, I should have closed this one off as resolved.
It was a mix of php and javascript scorcery. For anyone else's future reference I've posted my solution below (I've tried to comment it as much as possible):
//* Add support for hide news widgets if no posts
add_action( 'genesis_before', 'ybs_empty_category' );
function ybs_empty_category() {
//* Declare variables for each category you want to check
$charter=get_posts('category_name=charter-news');
$fares=get_posts('category_name=fares-and-tickets');
$school_transport_news=get_posts('category_name=school-transport-news');//* Make sure you're on the right page, then check if the category for that page has posts
if (is_page( 'charter' ) && $charter->post_count == 0) {
//* Use PHP to echo out javascript - See, SCORCERY!!!!
echo "
<script type=\"text/javascript\">
jQuery(document).ready(function() {
document.getElementById('news_charter').style.display = 'none';
});
</script>";
}
}
The large print giveth, and the small print taketh away.
– Tom Waits, “Step Right Up”May 1, 2014 at 9:17 pm #103273Tom
ParticipantThanks for the update and the code.
Choose your next site design from over 350 Genesis themes.
[ Follow me: Twitter ] [ Follow Themes: Twitter ] [ My Favourite Webhost ] -
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.