WordPress.org

Ready to get started?Download WordPress

Forums

Adding img & div tags in sidebar.php before each widget doesn't work (11 posts)

  1. kevinp93
    Member
    Posted 2 years ago #

    Hi there,

    I am setting up my first WordPress site and I have managed to screw something up.

    Basically I have set up a WordPress website on my server, and I am making it look like the main website. One of the 'features' on the site is that all the widgets have an image (paperclip) and a background colour (here's a screenshot).

    This is achieved by using the following img and div tags:

    <img class="paperclip" src="link" alt="paperclip" />
    <div class="sidebar">
         <!-- widget code-->
    </div>

    I managed to add this styling to the widgets in WordPress before by adding the img and div tags in front of every widget within sidebar.php of my theme (see below):

    <img class="paperclip" src="link" alt="paperclip" />
    <div class="sidebar">
         <li id="search" class="widget-container widget_search" style="list-style:none;">
              <?php get_search_form(); ?>
         </li>
    </div>

    My hard drive then stopped working and I had to re-install WordPress and stuff. The problem I'm having now is that I can't seem to add the styling to the widgets like I did before.

    Before my hardware failed, I was using WordPress 3.3.1. Now I'm using the latest 3.4 version. I don't think there's a problem with the version of wordpress I'm using because I even tried installing the old version and making the same changes.

    Luckily I had the whole WordPress folder backed up on my system (just before hhd crashed), so I tried uploading the files, but the widgets still don't appear like before.

    So what am I missing? Or what would you suggest I do to add the same styling to the widgets in wordpress?

    Your help is much appreciated. Thanks.

  2. Frumph
    Member
    Posted 2 years ago #

    do this with CSS instead having the paperclip image as a background: url( enclosing the wrapper of the widget.

    for example

    .widget-container {
          background: url(link) top center no-repeat;
          height: 300px;
          width: 200px;
          display: block;
    }

    If that doesn't work for you because of variable height of widgets, you can edit the function that registers the sidebars to add a <div class="widget-head"></div> to it, so that you then use that .widget-head instead.
    `

  3. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    are you hard-coding this into sidebar.php?

    or are you using this within the 'register_sidebar()' function in functions.php of your theme?

    are you using widgets from within 'dashboard - appearance - widgets'?

    what is the result at the moment?

    can you post a link to your site to illustrate what you have now?

  4. kevinp93
    Member
    Posted 2 years ago #

    @Frumph: Thank you. I'll give it a shot later and tell you how it's going.

    @Alchymyth: Yes. I hard-coded the code into sidebar.php. And the only widgets that I'm using at the moment are 'Search', 'Archieves' & 'Meta'. And at the moment there is no styling. The main site is : enfieldsdachurch.com and the blog is at http://www.blog.enfieldsdachurch.com. (Please note that the server is down between 11pm and 8am UK time)

  5. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    seems you are using widgets, in which case the hard-coded section might not get applied;

    please paste the full code of sidebar.php into a pastebin.com and post the link to it here - HOWTO.

  6. kevinp93
    Member
    Posted 2 years ago #

    Thank you for your reply. Here's the code used in sidebar.php that worked before I re-installed wordpress.

    I appreciate your help.

  7. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    everything from line 18 to line 48 will not get used if you are using real widgets within dashboard - appearance - widgets - as you are doing now.

    goto dashboard - appearance - widgets and remove all widgets from the primary and secondary widget areas.

    guess - possibly before the update you were not using widgets, but relying on your hardcoded output.

  8. kevinp93
    Member
    Posted 2 years ago #

    Ok I understand. So how would I be able to add the custom styling to 'real widgets'?

    I'm a newbie and I'm just getting started with all this programming so please bear with me :)

  9. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    have you tried to drag the widgets off the widget areas?
    and what was the result?

    add the custom styling to 'real widgets'

    you need to edit the way the sidebars are registered in functions.php:

    codex chapter:
    register_sidebar() http://codex.wordpress.org/Function_Reference/register_sidebar

    i.e. the 'before_widget' and 'after_widget' arguments.

    try:

    register_sidebar(array(
      'name' => __( '????keep what you have here????' ),
      'id' => '????keep your id????',
      'description' => __( '????keep your text????' ),
      'before_widget' => '<img class="paperclip" src="http://dev.enfieldsdachurch.com/images/paperclip.png" alt="paperclip" />
                    <div class="sidebar">
                            <li id="%1$s" class="widget-container %2$s" style="list-style:none;">
    ',
      'after_widget' => '</li></div>'
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>'
    ));

    (btw: the use of 'div' in the code will generate invalid html code; although most browsers will display it somehow)
    possibly try to change 'div' to 'ul' in the above code.

    if you have problems, you can paste your register_sidebar() code into a pastebin and post the link to it here.

  10. kevinp93
    Member
    Posted 2 years ago #

    I just tried removing all the widgets and yes it works like you said :)

    Thanks for the link. I'll go over the stuff and make the appropriate changes. If there are any problems I'll update the post.

    Thank you. Your help is much appreciated.

  11. kevinp93
    Member
    Posted 2 years ago #

    Hi there,

    Thank you for your help. I have managed to get it to work.

    You were right about using the div tags. I tried adding the div tags in and IIS gave me a 500:Internal Server error.

    But to get around that I just removed the div tags and styled using the list (widget-container).

    Thank you once again. :)

Topic Closed

This topic has been closed to new replies.

About this Topic