Increment widget div style in functions.php (5 posts)

  1. Gareth_Roberts
    Posted 4 years ago #

    I need to apply a new style for the second widget on each page. The first widget on a page will have one style and all additional widgets will have another. There should only be 2 on any page.

    The first widget: <div id="firstWidget">
    The second widget: <div id="extraWidget">

    Currently my functions.php file contains:
    if ( function_exists('register_sidebar') )
    'name' => 'Sidebar',
    'before_widget' => '<div id="firstWidget">',
    'after_widget' => '</div>',
    'before_title' => '<h2>',
    'after_title' => '</h2>',

    I've seen users ask the same question but with no responce.

  2. Michael
    Forum Moderator
    Posted 4 years ago #

  3. Gareth_Roberts
    Posted 4 years ago #

    Thanks for the reply. I found this article yesterday but could extract the info I need. I'm afraid my knowledge of PHP is fairly limited.

    I've tried adding id="%1$s" but it gives every widget in my site a new number. So I would need to create 30+ styles!!

    Any more ideas?

  4. Gareth_Roberts
    Posted 4 years ago #

    If it helps the web page is http://www.ventureaccounting.co.uk/accountancy-services/

    I simply want the second widget to have a new id.

  5. Gareth_Roberts
    Posted 4 years ago #

    I'm getting closer but still need help.

    I've added '.$i.' inside my div

    I've also added <?php $id=1; $i++ ?> to the start of my funtion.php file.
    This adds 1 to my style but no increment(box2, box3...)

Topic Closed

This topic has been closed to new replies.

About this Topic