Forums

Showing a widget on just the main page? (23 posts)

  1. britneyspy
    Member
    Posted 3 years ago #

    Is there a way to only show a widget on the main blog page?

    I have a widget with links to other sites, I only want them to appear on the main page, instead of being on all the post pages too.

    Is there a way to make this widget only display on 1 page?

    Thanks

  2. alanft
    Member
    Posted 3 years ago #

  3. britneyspy
    Member
    Posted 3 years ago #

    Thanks a lot, I installed the plugin but I'm not quite sure what to put in the Widget Logic field for it to only display on the main page?

  4. alanft
    Member
    Posted 3 years ago #

    it depends on what you mean by the main page. have a look down http://codex.wordpress.org/Conditional_Tags

  5. britneyspy
    Member
    Posted 3 years ago #

    Well, I'm not sure if I mean Front Page or Main Page, this is the page I mean:

    http://www.britneyspy.com/

    I read the Conditional Tags page and still wasn't sure what to do, so I put "is_front_page()" in the Widget Logic field and it gave me an error:

    Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/bspy/public_html/wordpress/wp-content/plugins/widget-logic/widget_logic.php on line 29

    Warning: Invalid argument supplied for foreach() in /home/bspy/public_html/wordpress/wp-content/plugins/widget-logic/widget_logic.php on line 29

    Warning: Cannot modify header information - headers already sent by (output started at /home/bspy/public_html/wordpress/wp-content/plugins/widget-logic/widget_logic.php:29) in /home/bspy/public_html/wordpress/wp-includes/pluggable.php on line 770

    Thanks again for the help!

  6. alanft
    Member
    Posted 3 years ago #

    i can see you are on 2.6 though - i've not upgraded yet. perhaps it is an incompatibility with 2.6 and my plugin. sorry. i will check that. the plugin isn't listed as being 2.6 compatible yet. sorry again.

    i can't get the same results on 2.5 - i even went back to a new install, installed widget-logic and pasted in the same text. no problem.

    (if you persist with the plugin and ever work out what causes this problem, i'd love to know.)

  7. britneyspy
    Member
    Posted 3 years ago #

    ok, ill keep trying and let you know!

  8. doodlebee
    Member
    Posted 3 years ago #

    You haven't said if you're using a static page (in your settings) as the index page, or if you're just using the regular blog posts as your index page. There's a big difference.

    If you're using the default setup, then you want to use "if(is_home())". If you're using a Page page as your index page, *then* you use "if(is_front_page())".

  9. alanft
    Member
    Posted 3 years ago #

    just checked a 2.6 install and widget-logic is working ok on it. and is_front_page() is working ok to show a specific widget on just the front page

    :-/

    so still no idea why yr getting those errors out of it. and looking at the code it seems crazy that you should (though my experience of PHP5 is nil, the code looks innocuous in terms of staying compatible).

  10. britneyspy
    Member
    Posted 3 years ago #

    I´ve spent about an hour trying to work around the error but I´m still getting nothing :-\

  11. doodlebee
    Member
    Posted 3 years ago #

    I don't know what "widget logic" is (aside from reading the link above) but my advice wasn't encompassing that particular plugin. The error you're getting looks like it's coming from the plugin - and in that case, I'd contact the plugin author.

    But if you want to display a widget on the index page only, it would help to know if you were using a static Page as your index page to not - because that determines which conditional you need to use in your sidebar code (as specified in my previous post).

    If you only want a *specific* widget to display on the index page (and other widgets for other pages) then you need to create a "second sidebar" (as described at the bottom of this page), and then add your conditional to that one.

  12. britneyspy
    Member
    Posted 3 years ago #

    well on the settings > reading page, i have it set to display "your latest posts"

    http://www.britneyspy.com > i want all the widgets to show in the sidebar on that page, but on ALL the other pages i dont want 1 of the widgets to show (the links)

    i hope that makes it a bit clearer, i'm confusing myself now to be honest!

  13. doodlebee
    Member
    Posted 3 years ago #

    Ah, okay.

    Well then you want the "if(is_home())" option.

    You'll also want to create a secondary sidebar.

    So, in your functions.php file, you'll have:

    if ( function_exists('register_sidebar') ) {
      register_sidebar(array(
         'name'=>'Index Page Sidebar',
         'before_widget' => '<div id="%1$s" class="widget %2$s">',
         'after_widget' => '</div>',
         'before_title' => '<h3>',
         'after_title' => '</h3>',
        ));
      register_sidebar(array('name'=>'Regular Sidebar',
         'before_widget' => '<div id="%1$s" class="widget %2$s">',
         'after_widget' => '</div>',
         'before_title' => '<h3>',
         'after_title' => '</h3>',
        ));
      }

    then, in your sidebar.php file (or wherever your sidebar widgets stuff is):

    if(is_home()) {
    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Index Page Sidebar') ) :?>
    stuff if you don't use widgets here
    <?php endif; } //end index page only stuff
    if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Regular Sidebar') ) : ?>
    stuff if you don't use widgets here
    <?php endif; ?>

    Then in your widgets area, you'll have two sidebars to choose from in the dropdown. The "regular" sidebar, you can put the stuff you want to show up everywhere, and the "Index" page one you add the widgets you want only for the index page.

  14. britneyspy
    Member
    Posted 3 years ago #

    I wish I had just left well alone now, I backed up those 2 files and tried that code, but it gave me an error, so I reuploaded the original files and now the sidebar doesn't display!

    It's just a blank column and when I go into Widgets in the Admin Panel it says "No Sidebars Defined" in a red box :(

    I have no idea how to fix it now, any suggestions?

  15. doodlebee
    Member
    Posted 3 years ago #

    What was the error?

  16. myrko
    Member
    Posted 3 years ago #

    I added is_home() to the widget criteria in the admin widget-selection. But it seems to be ignored totally. It is the lower right Ad on http://www.awakeblogger.com , any ideas?

    Thx,
    Myrko

  17. alanft
    Member
    Posted 3 years ago #

    i have no idea. what theme is that? if i had the theme i could test it on another setup to see what's going on. (the sidebar looks quite complex)

  18. myrko
    Member
    Posted 3 years ago #

    It is the IMWW Theme: http://iamww.com/wordpress-theme-iamww-w2/ which is quit commonly in use these days. Thx for your help!

  19. alanft
    Member
    Posted 3 years ago #

    there is no way to download that -- it's got 'no longer supported' written all over it and a link to "IAMWW w2 DnD". what happens when you use that theme instead? same issue?

  20. myrko
    Member
    Posted 3 years ago #

    Im sorry, the correct link to my theme is the one you mentioned: http://iamww.com/wordpress-theme-iamww-w2-dnd/ . It is pretty up2date.

    I checked with another theme and there is_home() works. Any hints?

  21. alanft
    Member
    Posted 3 years ago #

    i think i'll have to try this out on a fresh WP install, but i'm not clear looking at the themes code and your site. has your theme been customised?

    first off, is the widget you are talking about the 'google adsense' under the recent comments gravatars? that's the 4th in a mini sidebar of polls/tags/recentcomments/adsense/now-reading.

    the UL for that sidebar doesn't have an ID, and though the theme sidebar.php ends

    </div><!-- end sbwidgets-->
    </div><!--end sidebar-->

    this sidebar is between those two comments. so i don't know what's going on there. there's nothing unusual in functions.php that could be messing things up either.

    like i say, it might be clearer if i try to install it on my local LAMP version at home. will let you know if anything obvious jumps out at me.

  22. alanft
    Member
    Posted 3 years ago #

    ok - it rly does look like your theme has been customised quite a lot.

    i think there must be 'hard coded' widgets above and below the drag-and-drop widgets you can configure in the WP admin interface - the std sidebard for that theme is just a double sidebar with a single 'about' at the top that spans them both (and a few other bits and piece like 'recent posts' on archive pages and so on). yours has lots more above and below spanning both columns including the adsense widgets

    so i think the problem is that the widget you want to configure isn't configured from the WP interface. so widget-logic doesn't get a look in.

    check your sidebar.php against a fresh copy of the downloaded theme. you may even be able to get your modifications improved so that the extra widgets are in a 3rd configurable sidebar

    i might be wrong in this - but it seems very likely on the face of it.

  23. Nax969
    Member
    Posted 3 years ago #

    How can you do the opposite (for it to appear everywhere except main page)?

Topic Closed

This topic has been closed to new replies.

About this Topic