1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Show widgets in frontpage only

Discussion in 'WordPress' started by Divvy, Sep 19, 2014.

  1. #1
    Hi guys,

    I need a little help here, can someone help me? :)

    I'm trying to make an specific widget to appear in my blog frontpage only, but I cant figure out...
    I already tried plugins like Widget Logic but didn't worked.
    I know that I need to use is_home() or is_frontpage() in the code but it seems that nothing works.

    My theme already have a section to add widgets in homepage, but it seems that is not working, because the widgets appears in pagination (only I think) too...

    [​IMG]

    Here are some code of my theme:

    functions.php
    http://paste2.org/YVx8fbvK

    sidebar.php
    http://paste2.org/WYNYxknX

    Can someone give me a solution, please? :)

    Thanks!
     
    Divvy, Sep 19, 2014 IP
  2. Xtrapsp

    Xtrapsp Active Member

    Messages:
    716
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    90
    #2
    One thing you can do is create your own widget areas

    Basically you make a widget and then paste this:

    
    <?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
    <div id="primary-sidebar" class="primary-sidebar widget-area" role="complementary">
    <?php dynamic_sidebar( 'sidebar-1' ); ?>
    </div><!-- #primary-sidebar -->
    <?php endif; ?>
    
    Code (markup):
    Wherever you need it. In most cases, that is index.php
     
    Xtrapsp, Sep 19, 2014 IP
  3. Divvy

    Divvy Well-Known Member

    Messages:
    781
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #3
    Thank you for your reply and help buddy!

    I copy that code to my index.php file, but like the sidebar that I already have, the widgets appears in all pages.

    To be honest, I just need a little help in my current code, can you fix it? :)

    I think the solution is in this part of the code of functions.php file:
    function wptThemeRegisterSidebars() {
    register_sidebar(array(
    'name' => 'Main Page',
    'description' => 'Widgets will be shown on the main page',
    'before_widget' => '<div class="side_cont"><div class="side_cont_top"><div class="side_cont_bttm">',
    'after_widget' => '</div></div></div></div>',
    'before_title' => '<div class="side_title">',
    'after_title' => '</div><div class="side_content">',
    ));
    PHP:
    Or here in sidebar.php file:

    if ( is_single() && is_active_sidebar( 2 )) {
    dynamic_sidebar(2);
    } else if ( is_home() && is_active_sidebar( 1 )) {
    dynamic_sidebar(1);
    } else if ( is_page() && is_active_sidebar( 3 )) {
    dynamic_sidebar(3);
    } else {
    dynamic_sidebar(4);
    }
    PHP:
    Note: The strange part is that this is kind of working to show in index only. Except in pagination... when I go to any page, the widget appears and is not supposed to.
     
    Divvy, Sep 19, 2014 IP
  4. Divvy

    Divvy Well-Known Member

    Messages:
    781
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #4
    Please, anyone? :)
     
    Divvy, Sep 21, 2014 IP
  5. rajgupta

    rajgupta Well-Known Member

    Messages:
    207
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    155
    #5
    Hi.

    Sorry if this is of no help but comparing the function reference on wordpress codex and your codes (function and sidebar), you might be calling the functions wrong. You are not declaring any "ID" for the sidebar and then trying to reference to them using IDs 1, 2, 3 etc...

    Here is the codex function reference -

    function theme_slug_widgets_init() {
    register_sidebar( array(
    'name' => __( 'Main Sidebar', 'theme-slug' ),
    'id' => 'sidebar-1',
    'description' => __( 'Widgets in this area will be shown on all posts and pages.', 'theme-slug' ),
    'before_title' => '<h1>',
    'after_title' => '</h1>',
    ) );
    }
    add_action( 'widgets_init', 'theme_slug_widgets_init' );

    Also I guess you can try this instead - http://www.wpbeginner.com/wp-themes/how-to-add-dynamic-widget-ready-sidebars-in-wordpress/

    Hope that helps :)
     
    rajgupta, Sep 21, 2014 IP
  6. Jameyson MacDonald

    Jameyson MacDonald Well-Known Member

    Messages:
    452
    Likes Received:
    83
    Best Answers:
    3
    Trophy Points:
    115
    #6
    Jameyson MacDonald, Sep 21, 2014 IP
  7. Divvy

    Divvy Well-Known Member

    Messages:
    781
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #7
    rajgupta, unfortunately the "trick" didnt worked :(

    Jameyson MacDonald, thank you buddy, but it seems that plugins dont work too.

    Well, the widgets are working like I want some how, the only section that the widgets appears is in the pagination.
    Could be a pagination issue?

    Any ideas guys?
     
    Divvy, Sep 22, 2014 IP
  8. themes4all

    themes4all Well-Known Member

    Messages:
    662
    Likes Received:
    47
    Best Answers:
    6
    Trophy Points:
    100
    #8
    Hello there,

    you have to combine 2 plugins : Install Widget Logic Plugin, Then install Widget Logic by Path Plugin.

    Open the widget that you want to Show only in Homepage and Select the Options :) That's all

    Goodluck
     
    themes4all, Sep 22, 2014 IP