ThemeShaper Forums » Thematic

[closed]

Adding a widget inside a div to the Homepage Only

(13 posts)
  • Started 12 years ago by lance1572
  • Latest reply from lance1572
  • This topic is not resolved
  1. lance1572
    Member

    Hi everyone!

    First time caller, long time lurker :)

    I'd like to add a widget inside a div only on the homepage (just below the header but inside the main div before the container div). What I have begun was to register a sidebar widget in the functions.php as well as create a div there to hold the widget. Problem is I cannot seem to get it only to show only on the homepage. I'm new to php and understand that I could use a conditional but I do not know how to exactly write one. I'd appreciate any help!! Thank you!

    Here's what I've got so far.

    function div_intro_open() { ?>
    <div id="intro-holder" >
    <?php }

    add_action('thematic_abovecontainer', 'div_intro_open');
    add_action('thematic_abovecontainer','show_new_widget_area');

    function div_intro_close() { ?>

    </div>
    <?php }

    add_action('thematic_abovecontainer', 'div_intro_close');

    if (function_exists('register_sidebar')) {
    register_sidebar(array(
    'name'=> 'Intro Aside',
    'id' => 'intro-aside',
    'description' => 'This is where your header widgets go',
    'before_widget' => '<h3 id="%1$s" class="widget %2$s">',
    'after_widget' => '</h3>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h2>',
    ));
    }

    function show_new_widget_area(){
    if (function_exists('dynamic_sidebar')){
    dynamic_sidebar('intro-aside');
    }
    }

    Posted 12 years ago #
  2. you could check out: http://forums.themeshaper.com/topic/something-new-bout-widgetized-areas#post-6660

    but if the above code works in the sense that the widget appears everywhere then you just need to apply your conditional to the output

    function show_new_widget_area(){
    if (function_exists('dynamic_sidebar') && is_home()){
    dynamic_sidebar('intro-aside');
    }
    }

    if your home page is your blog page. otherwise you might need to use is_front_page()

    full list of wordpress conditionals
    http://codex.wordpress.org/Conditional_Tags

    Posted 12 years ago #
  3. lance1572
    Member

    Thanks! Helga! I see you are on here quite a lot helping everyone out!!!! Much respect!!! I'll give it a go and thank you again!!!

    Posted 12 years ago #
  4. lance1572
    Member

    Ok...Got it to work only on the hompeage....but I'm not sure how to call the display function when creating the div

    // Create Widget

    function add_welcome_aside($content) {
    $content['Welcome Aside'] = array(
    'args' => array (
    'description' => 'Put Your Welcome Message Here - This will go underneath the sub-header rotator',
    'name' => 'Welcome Aside',
    'id' => 'welcome-aside',
    'before_widget' => thematic_before_widget(),
    'after_widget' => thematic_after_widget(),
    'before_title' => thematic_before_title(),
    'after_title' => thematic_after_title(),
    ),
    'action_hook' => 'thematic_abovecontent',
    'function' => 'thematic_welcome_aside',
    'priority' => 100,
    );
    return $content;
    }
    add_filter('thematic_widgetized_areas', 'add_welcome_aside');

    // And this is our new function that displays the widgetized area

    function thematic_welcome_aside() {
    if (is_sidebar_active('welcome-aside') && is_page_template('page-front.php')) {
    echo thematic_before_widget_area('welcome-aside');
    dynamic_sidebar('welcome-aside');
    echo thematic_after_widget_area('welcome-aside');
    }
    }

    // This is where I create the div to hold the widget ---- This where I get lost....How do I get the widget to display inside of the div

    function wrap_welcome_widget() { ?>
    <div id="welcome-intro">

    <?php }
    add_action('thematic_abovecontent','wrap_welcome_widget',1);

    function wrap_welcome_widget_close() { ?>
    </div>
    <?php }
    add_action('thematic_abovecontent', 'wrap_welcome_widget_close', 9);

    Posted 12 years ago #
  5. lance1572
    Member

    Got it!!!! I was having simple trouble with placing the php tags - so with a little trial and error.

    HUGE Thank you to Helga (You Rock!!!) who got me going in the right direction and some code!!!!! Thank you!!

    Here what I did....may not be right but it works (at least for now :)

    // Register Widget

    if (function_exists('register_sidebar')) {
    register_sidebar(array(
    'name'=> 'Intro Aside',
    'id' => 'intro-aside',
    'description' => 'This is where your header widgets go',
    'before_widget' => '<h3 id="%1$s" class="widget %2$s">',
    'after_widget' => '</h3>',
    'before_title' => '<h3 class="widgettitle">',
    'after_title' => '</h2>',
    ));
    }

    //Display widget inside a newly created DIV on on the home page only

    function show_new_widget_area(){
    if (function_exists('dynamic_sidebar') && is_page_template('page-front.php')){ ?>
    <div id="welcome-intro">
    <?php dynamic_sidebar('intro-aside');?>
    </div>
    <?php
    }

    }
    add_action('thematic_abovecontent','show_new_widget_area');
    ?>

    Posted 12 years ago #
  6. lance1572
    Member

    This worked but now my homepage is loading slower. I created 4 more widgets and divs simply by cutting and pasting the above code 4 times....editing the areas that needed it. Is there a way to combine all of them possibly into an array?

    Posted 12 years ago #
  7. not unless you do it the way i linked to before:
    http://forums.themeshaper.com/topic/something-new-bout-widgetized-areas#post-6660

    and that isn't going to save you a whole lot of code anyway.

    not surprising that your home page is loading slower... you're loading more content. always a fine line between adding cool stuff and slow wait times.

    why do you need 4 new widget areas? are they going in different places? thematic has a gazillion already... so many that i usually have to strip them out for client projects.

    Posted 12 years ago #
  8. lance1572
    Member

    I'm creating a homepage with 4 new cols like the subsidiary cols but only on the homepage. I'm using the subs now and that is why I have created new areas.

    I've got everything working good and the site is loading super fast. Previously, I was on a test box and the install was a couple of directories down.

    :)

    Posted 12 years ago #
  9. lance1572
    Member

    Quick question. I apologize if this has been answered.

    When you create these areas, how do you get the ability to print out in a specific area in the code?

    Example: I've added a new area (news-extra-content) and want to be placed after container - so I used thematic_belowcontainer which is great but how do I control where it gets placed in the html? Right now it gets printed above the secondary, primary, and tertiary. I'd like for it to get printed after the primary, secondary, and tertiary.

    <div id="main">
    <div id="container">
    </div>
    <div id="news-extra-content"> </div>
    <div id="primary" class="aside main-aside">
    </div>
    <div id="secondary" class="aside main-aside">
    </div>
    <div id="tertiary"> </div>

    Posted 12 years ago #
  10. thematic_belowcontainer() will put your content, not too shockingly, below the #container.

    if you want something after primary and secondary then you need

    thematic_belowmainasides()

    or

    thematic_abovefooter()

    see this for reference:
    http://visualizing.thematic4you.com/

    Posted 12 years ago #
  11. lance1572
    Member

    You are quick!!!! I was writing this as you wrote back!

    I think there may be another way to skin a cat. :)

    If I use this hook....thematic_abovefooter I can achieve basically what I want.

    was wondering if there is another way because technically I'd like for it to be placed last in the main div and not outside of it.

    TY - I have that link bookmarked :)

    Worked....thematic_belowmainasides() You are the BEST/......you know that right!!!??!

    Posted 12 years ago #
  12. yes i know, but i never tire of hearing it. . ;)

    that site and
    http://www.bluemandala.com/thematic/thematic-structure.html

    should be in your reference folder

    Posted 12 years ago #
  13. lance1572
    Member

    Oh! Nice!!!! Thank you!

    Posted 12 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.