WordPress.org

Ready to get started?Download WordPress

Forums

Tempera
Some Widgets on Front Page (9 posts)

  1. majselx
    Member
    Posted 4 months ago #

    Is it possible to add some widgets on the left or right side of the front page? Or somewhere else. They just need to be widgets with some HTML text. Thank you!

  2. onedna
    Member
    Posted 4 months ago #

    Add this code in function.php:

    register_sidebar( array(
      'name' => __( 'Leftwidget', 'tto' ),
      'id' => 'lefthome',
      'description' => __( 'Found at the bottom of every page (except 404s, optional homepage and full width) as the footer. Left Side.', 'tto' ),
      'before_widget' => '<aside id="%1$s" class="widget %2$s">',
      'after_widget' => '</aside>',
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
    ) ); 
    
    register_sidebar( array(
      'name' => __( 'rightwidget', 'tto' ),
      'id' => 'righthome',
      'description' => __( 'Found at the bottom of every page (except 404s, optional homepage and full width) as the footer. Left Side.', 'tto' ),
      'before_widget' => '<aside id="%1$s" class="widget %2$s">',
      'after_widget' => '</aside>',
      'before_title' => '<h3 class="widget-title">',
      'after_title' => '</h3>',
    ) );

    Add this code in index.php(or where you want to add widgets)

    <?php if ( is_active_sidebar( 'lefthome' ) ) : ?>
                <?php dynamic_sidebar( 'lefthome' ); ?>
              <?php endif; ?> 
    
    <?php if ( is_active_sidebar( 'righthome' ) ) : ?>
                <?php dynamic_sidebar( 'righthome' ); ?>
              <?php endif; ?>

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

  3. esmi
    Forum Moderator
    Posted 4 months ago #

    @majselx: Do not edit the theme itself. First create a child theme for your changes.

    @onedna: Please do not encourage people to edit theme files directly. At best, they will lose all of their changes when they update the theme.

  4. majselx
    Member
    Posted 4 months ago #

    I've created the child theme. I'll try the code now and get back to you guys. Thank you.

  5. majselx
    Member
    Posted 4 months ago #

    @onedna: I did what you said. Now the website doesn't even load. It's just blank.

  6. onedna
    Member
    Posted 4 months ago #

    @majselx:
    Are you sure you have created the child theme in correct way, I sugegst you to remove the new code and check if the child theme is working well. You can check the child theme guide here https://codex.wordpress.org/Child_Themes

    Thanks

  7. majselx
    Member
    Posted 4 months ago #

    I managed to do it, but the widgets now show at the bottom of the page.

    Is it possible to add three widgets instead of that text (see the picture below):

    http://i.imgur.com/UPcmGCV.png

  8. onedna
    Member
    Posted 4 months ago #

    You need the place the code

    <?php if ( is_active_sidebar( 'lefthome' ) ) : ?>
                <?php dynamic_sidebar( 'lefthome' ); ?>
              <?php endif; ?> 
    
    <?php if ( is_active_sidebar( 'righthome' ) ) : ?>
                <?php dynamic_sidebar( 'righthome' ); ?>
              <?php endif; ?>

    on desired location

  9. majselx
    Member
    Posted 4 months ago #

    Where should I put that in index.php? My index.php has only this code:

    get_header();
    if ($tempera_frontpage=="Enable" && is_front_page() && !is_page()): get_template_part( 'frontpage' );
    // if is_page() -> additional check in page.php
    else: get_template_part('content/content', 'index');
    endif;
    get_footer();

Reply

You must log in to post.

About this Theme

About this Topic

Tags

No tags yet.