Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDan Barrett
10,450 PointsHelp with custom widget areas
I am following how to create a custom theme but having issues when adding in custom widget areas to the footer.
Dan Barrett
10,450 Pointshi, so the problem I ma facing is that I have added the 3 custom widget areas to the footer. I have added the code into functions.php as follows:
function create_widget( $name, $id, $description ) { $args = array( 'name' => __( $name ), 'id' => $id, 'description' => $description, 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h5>', 'after_title' => '</h5>' );
register_sidebar( $args );
} create_widget( 'Left Footer', 'footer_left', 'Displays in the bottom left of footer' ); create_widget( 'Middle Footer','footer_middle', 'Displays in the middle of footer' ); create_widget( 'Right Footer', 'footer_right', 'Displays in the bottom right of footer' );
the widget areas show within the admin area, but when I drag a widget over the content remains th same, here is the code within the footer.php file:
<div class="grid_4 footer-left"> <?php if( dynamic_sidebar( 'footer-left' ) ): ?> <?php else: ?>
<h5>Twitter</h5>
<p>Install the TwiGet plugin and place the widget here in the left bottom footer</p>
<?php endif; ?>
</div>
<div class="grid_4 footer-middle">
<?php if( dynamic_sidebar( 'footer-middle' ) ): ?>
<?php else: ?>
<h5>dribbble</h5>
<p>Install the dribbble plugin and place the widget here in the left bottom footer</p>
<?php endif; ?>
</div>
<div class="grid_4 omega footer-right">
<?php if( dynamic_sidebar( 'footer-right' ) ): ?>
<?php else: ?>
<h5>Treehouse</h5>
<p>Install the treehouse plugin and place the widget here in the left bottom footer</p>
<?php endif; ?>
</div>
Dan Barrett
10,450 PointsI apologise for the format of my previous comment I wasn't sure on how to format it correctly as there are no options. However I am really really in need of help so anything would be greatly appreciated :)
2 Answers
Christopher Rebacz
10,904 PointsHi Dan--
The problem looks like it is in your footer.php file. Your current code checks to see if the sidebar exists and provides an action in case it doesn't ('else'), but it doesn't provide any code to run when your conditional statement returns true. So you just need to add the actual call to the dynamic_sidebar function in the 'if' part of your statement.
<?php if( dynamic_sidebar( 'footer-middle' ) ) : dynamic_sidebar('footer-middle'); ?>
Dan Barrett
10,450 PointsSo it now looks like this...
<?php if( dynamic_sidebar( 'footer-left' ) ) : dynamic_sidebar('footer-left'); ?>
<?php else: ?>
<h5>Twitter</h5>
<p>Install the TwiGet plugin and place the widget here in the left bottom footer</p>
<?php endif; ?>
It still isn't changing the content out? I am a bit stuck
Zac Gordon
Treehouse Guest TeacherDouble check the code sample again and simplify your code to just get one widget area working first. Having those two parts in the if statement does not follow the same convention I believe the examples do.
Dan Barrett
10,450 PointsHey Zac
It was the naming convention that was the issue because underscores where being used I switched them and now works just fine :)
great tuts btw following all the Wordpress stuff not really running into any issues aside from this but really enjoying them. Very informative and easy to follow!
Dan
Muhammad Mohsen
Courses Plus Student 10,843 PointsMuhammad Mohsen
Courses Plus Student 10,843 PointsHi Dan,
Please give us more info about what you are doing with code snippets.