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 trial

WordPress

Kyle Barney
Kyle Barney
9,081 Points

Widgets Not Appearing in Widgetized Wordpress Areas

It looks like I've been able to get my sidebar.php to port into my pages (archive.php) for example, but when I enable the widgets in the Wordpress admin area, none of them show up in my widgetized areas. (If I put something else (like a heading or div) into sidebar.php, it makes it through into the final rendering of the page, but none of the widgets come through. Any ideas?

Sidebar.php

 <?php dynamic_sidebar('sidebar_widgets'); ?>

Functions.php

function wp_ua_create_widget( $name, $id, $description ) {
    register_sidebar(array(
        'name' => __( $name ),
        'id' => $id,
        'description' => __( $description ),
        'before_widget' => '<div class="widget">',
        'after_widget' => '</div>',
        'before_title' => '<h2 class="module-heading">',
        'after_title' => '</h2>'
    ));
}

wp_ua_create_widget( 'Sidebar Widgets', 'sidebar_widgets', 'Displays in the sidebar' );

Archive.php

<?php get_sidebar(); ?>

2 Answers

Stanley Thijssen
Stanley Thijssen
22,831 Points

Your code seem to be fine. May i ask how your archive.php looks like? or you just have get_sidebar() in it?

Kyle Barney
Kyle Barney
9,081 Points

Here's the archive.php file - (pardon the ugliness, nothing is styled yet - just trying to get the skeleton in place.)

<?php
/*
  Template Name: Right Sidebar
*/
?>

<?php get_header(); ?>

<!--Place Code to Create Primary Content Column Here-->

<div class="leader">
  <h1><?php wp_title(''); ?> Blog Posts</h1>
</div

<!--Start WP Loop (Container elements should be outside the loop, repeated elements should be inside the loop)-->

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<h1><a href='<?php the_permalink(); ?>'><?php the_title(); ?></a></h1>
<ul class="post-meta no-bullet">
  <li class="author">By <?php the_author_posts_link(); ?></li>
  <li class="cat">in <?php the_category(', '); ?></li>
  <li class="date">on <?php the_time('F j, Y'); ?></li>
</ul>
<?php if(get_the_post_thumbnail() ) : ?>
  <div class="img-container">
    <?php the_post_thumbnail('small'); ?>
  </div>
<?php endif; ?>
<p><?php echo strip_tags(get_the_excerpt() ); ?></p>

<!--End WP Loop-->

<?php endwhile; else : ?>
    <p><?php _e( 'Sorry, the page could not be found.' ); ?></p>
<?php endif; ?>

<!--Place Code to Create Sidebar Column Here-->

<?php get_sidebar(); ?>

<?php get_footer(); ?>