September 13, 201115 yr Hi, I am busy coding my first wordpress template and so far so good, go the header, footer and the content all in but I am stuck with the widgets. How do I code the wordpress widgets into the sidebar.php? its got my head spinning so if you have any advice or links to some good resources I would really appreciate the help. Thanks,
September 13, 201115 yr To be a bit more precise you can add in: <?php if ( function_exists('register_sidebar') ) register_sidebar(array( 'before_widget' => '', 'after_widget' => '', 'before_title' => '', 'after_title' => '', )); ?> into your functions.php file (if you don't have one just make it, put that in it and save it as functions.php) And add in: <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?> into sidebar.php, but keep the sidebar widgets you'd like hardcoded into the theme. If no custom widgets are added, the hardcoded ones are displayed. Make sure you keep ^ that php inside the div containing your sidebar so you can control it Hope that helps. If you're still a bit confused just let me know and I'll go into more details Edited September 13, 201115 yr by Malick
September 13, 201115 yr Author You should find all you need in the wordpress codex Ive been scouring in the wordpress codex all day an its become so confusing. To be a bit more precise you can add in: Thanks for the more detailed post, Ill defanitly give that a try ... I know I had to do something in the functions.php file but its all so confusing when you are doing something new. Ill keep at it and if I get stuck ill be sure to post an update , thanks for your help. I was able to hard code some "widgets" into my sidebar but thought having it all done in widgets will give the user the option to change the order around of the widgets or to remove some unwanted ones if they decided to change. or should I have both?
September 14, 201115 yr Ive been scouring in the wordpress codex all day an its become so confusing. Thanks for the more detailed post, Ill defanitly give that a try ... I know I had to do something in the functions.php file but its all so confusing when you are doing something new. Ill keep at it and if I get stuck ill be sure to post an update , thanks for your help. I was able to hard code some "widgets" into my sidebar but thought having it all done in widgets will give the user the option to change the order around of the widgets or to remove some unwanted ones if they decided to change. or should I have both? Yes you should have both. See put in the stuff you'd like in the sidebar as HTML in sidebar.php. But when you add the code i told you about and the user goes to "Appearance > Widgets" and adds a widget. It'll remove the hardcoded ones and replace them with the ones the user wants to have. If you want any HTML in particular before or after the widget or title just add it in between the apostrophes in the code i gave you to put into functions.php. For example if you wanted to add a div class to every widget you'd change: 'before_widget' => '', into 'before_widget' => '<div class="yourclass">', Simple
Create an account or sign in to comment