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

wordpress change location of widget

I am converting a normal site made with one.com and its going well.. Okay, but i have one question because if you look at the right part of the page she is telling about her meetings (it's in Danish) and i want to make a widget that only changes the things in there, how should i do it? Website here: http://bonusmorgruppe.dk/

4 Answers

Hi Mike,

Best way to do this is with a sidebar, this will let you add as many widgets as you would like.

You would need to register a sidebar, and add that sidebar to your template. Once that is done you can then drag and drop your widgets in this case a text widget into the sidebar in the WordPress admin.

Here is an example of the code needed:

functions.php

<?php

/**
 * Create Sidebar
 *----------------------------------------------------------------------------------------------//
 *
 */
  function create_widget($name, $id, $description) {

    register_sidebar(array(
      'name' => __( $name ),
      'id' => $id,
      'description' => __( $description ),
      'before_widget' => '<div id="%1$s" class="widget-wrap">',
      'after_widget' => '</div>',
      'before_title' => '<h3 class="widget-heading">',
      'after_title' => '</h3>'
    ));

  }
  // Create widgets
  create_widget( "My Sidebar",
                 "my-sidebar",
                 "Displays on the right of the page"
  );
/*----------------------------------------------------------------------------------------------*/

?>

template file you want the sidebar to display on

<?php

        <!-- this would just be added to the section of the template where you would like the sidebar to be shown -->
        <aside>
          <?php if( !dynamic_sidebar( 'my-sidebar' ) ): ?>

            <h3>SideBar Setup</h3>
            <p>Please add widgets in widgets area through admin!</p>

          <?php endif; ?>
        </aside>

?>

If you need any more help just let me know :)

Craig

It works fine now, but there is one problem. It only shows the content not the title. And i copied your first part and inserted it into funtions and the other part into my index.php like you told me to, what to do??

Hi Mike,

I had formatted my code in the question a little wrong so it might be worth checking over as ive now made the update.

Was it the Text widget you dragged over to the sidebar in the WP admin ?

Craig

it's still not showing the title and i'm just putting over the normal text widget

There should be a check box to "show widget title", also what theme are you using? Or are you building a theme from scratch?

Regards Craig

The thing is, my customer made a theme in the one.com web editor and then asked me to make it wordpress friendly and that is a new thing for me (im really new to this but i still know alot about php etc.) but because she made her website in the editor and the website needs to stay the same! im having problems with things such as navigation bar and the widgets. The website as i said is in Danish but take a look at it: Bonusmorgruppe.dk

I see Mike, not any easy one when I haven't a clue what the web pages are but I think I may have got the basics of what is going on.

All the pages are using the same sidebar on the right which means you only need a couple of things. It looks like there is only simple page content and possible a blog which is easily done and then it's down to styles which should also me pretty quick to get through.

Are you on a tight time scale for this to be done as I could put aside some time to help you better tomorrow if that was ok with you, probably have it done all in one day to be honest. At least for you to add the page content anyway.

Regards Craig

i can wait :)

No problem Mike, I will try and get us a starting point done today and get in touch tomorrow.

Do you have an email I can contact you on tomorrow to speed up communications?

Also are you in UK or where about so we can get times right ? Craig

mikster3420@gmail.com is my mail and im from Denmark right now here in denmark it's 11pm