Conditional Tags for Sidebar Content
-
Hello, I’m trying to learn how to use conditional tags in
areas such as sidebar.php so that I can have dynamic content there
such as a calendar widget, and fun facts widget on the home page and
no where else.I looked into codex and am trying to make this work, but I’m missing something I think.
<?php if ( is_home() ) { // add calendar widget to home page echo do_shortcode('[my_calendar format="mini" showkey="no"]'); } else {} ?>I got this one to work fine except obviously the title still shows on every page.
<div class="fun-facts-widget"><div id="fun-facts-widget-title">Fun Facts</div><?php if ( is_front_page() ){ if (function_exists (news_announcement)) news_announcement(); }?></div>I can’t figure out how to use the conditional tag while keeping the content wrapped in divs for styling and any extra markup like headlines, etc.
I just need a little assistance and I can be on my way I think. I’d appreciate any tips I can get. Still learning this stuff.
-
Ok, I have progress. Here is my code for anyone interested. Still have a lot to learn.
<?php if ( is_front_page() ) { // we're on the home page, so let's show a list of all top-level categories echo "<div id='fun-facts-widget-title'>"; echo "Fun Facts"; echo "</div"; echo "<div id='fun-facts-widget'>"; if (function_exists (news_announcement)) news_announcement(); echo "</div>"; echo "<div class='calendar-widget-frame'>"; echo do_shortcode("[my_calendar format='mini' showkey='no']"); echo "</div>"; } else { // catch-all for everything else (archives, searches, 404s, etc) echo ""; } // That's all, folks! ?>
The topic ‘Conditional Tags for Sidebar Content’ is closed to new replies.