Krenar Krenar - 6 months ago 9
PHP Question

How can I make , a footer section, visible only in my wordpress frontpage?

I have created 5 widgets sections for my template footer. Now I would like to know, how is possible to make a footer section only visible in my front page theme and the other widgets in all other pages? So footer 5 widget appears in front page and the footer4 in other pages!

Here is what I wrote, but it doesn't work!

<?php if (is_home()): if ( function_exists('dynamic_sidebar') && dynamic_sidebar(is_active_sidebar('footer5'))){?>
<div class="col-xs-12 col-sm-6 col-md-3">
<?php get_dynamic_sidebar('footer5'); ?>
</div><?php }?>
<?php elseif(is_active_sidebar('footer4')) : ?>
<div class="col-xs-12 col-sm-6 col-md-3 socialiconsfooter">
<?php dynamic_sidebar('footer4'); ?>
</div><?php endif; ?>

Answer

In order to print footer5 widget you need to change get_dynamic_sidebar('footer5') to dynamic_sidebar('footer5')

<?php
 if(is_home()):
    if(function_exists('dynamic_sidebar') && is_active_sidebar('footer5')){
        echo '<div class="col-xs-12 col-sm-6 col-md-3">';
        dynamic_sidebar('footer5');
        echo '</div>';
    }
    elseif(function_exists('dynamic_sidebar') && is_active_sidebar('footer4')){
        echo '<div class="col-xs-12 col-sm-6 col-md-3">';
        dynamic_sidebar('footer4');
        echo '</div>';
    }
 endif;
 ?>

The above code should work. It will show widget only on front page.

EDIT: To show widgets on every page the below code should work.

<?php
    if(function_exists('dynamic_sidebar') && is_active_sidebar('footer5')){
        echo '<div class="col-xs-12 col-sm-6 col-md-3">';
        dynamic_sidebar('footer5');
        echo '</div>';
    }
    elseif(function_exists('dynamic_sidebar') && is_active_sidebar('footer4')){
        echo '<div class="col-xs-12 col-sm-6 col-md-3">';
        dynamic_sidebar('footer4');
        echo '</div>';
     }
?>
Comments