WordPress.org

Ready to get started?Download WordPress

Forums

Add widget to end of page (10 posts)

  1. crookesa
    Member
    Posted 1 year ago #

    Hi,

    I want to add the widget (or another way) if possible for my latest 3 posts to the end of a page.

    I tried using a plugin but it caused trouble with my users not being able to edit sites.

    Is there any easy way to add the side widget for recent posts to the end of a page?

  2. Karun
    Member
    Posted 1 year ago #

    Put the following code in your functions.php file

    register_sidebar( array(
    'name' => 'Widget Name',
    'id' => 'widget-id',
    'description' => __( 'Widget Description'),
    'before_widget' => '<article class="grid_4 alpha">',
    'after_widget' => "</article>",
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ) );

    And put the following code where you want your widget to be displayed

    <?php if ( is_active_sidebar( 'widget-id' ) ) : ?>
    <?php dynamic_sidebar( 'widget-id' ); ?>
    <!-- #first .widget-area -->
    <?php endif; ?>

  3. crookesa
    Member
    Posted 1 year ago #

    Thanks I have done that but how do I find the widget-id?

    I presume I only need to change that on the code for the page where I want the widget inserted and leave the top snippet as posted?

  4. Karun
    Member
    Posted 1 year ago #

    For widget-id you can give any unique name you want like sidebar-2 , sidebar-right, etc

  5. crookesa
    Member
    Posted 1 year ago #

    I have added the code as you said and doesn't is being displayed.
    Am I missing something?

    Code inserted below:

    register_sidebar( array(
    'name' => 'Homepage Newsfeed',
    'id' => 'homepage-newsfeed',
    'description' => __( 'This is the news for the homepage below the text'),
    'before_widget' => '<article class="grid_4 alpha">',
    'after_widget' => "</article>",
    'before_title' => '<h2>',
    'after_title' => '</h2>',
    ) );
    <!--?php if ( is_active_sidebar( 'homepage-newsfeed' ) ) : ?-->
    <!--?php dynamic_sidebar( 'homepage-newsfeed' ); ?-->
    <!-- #first .widget-area -->
    <!--?php endif; ?-->
  6. crookesa
    Member
    Posted 1 year ago #

    @karunshakya45 Am i doing something wrong has still been trying this and cannot get it to work?

  7. Carlos Moreira
    Member
    Posted 1 year ago #

    check if the php opening tags are
    <?php ... ?>
    and not
    <!-- .... -->

  8. crookesa
    Member
    Posted 1 year ago #

    Thanks for the reply Carlos

    <?php if ( is_active_sidebar( 'homepage-newsfeed' ) ) : ?>
    <?php dynamic_sidebar( 'homepage-newsfeed' ); ?>
    <!-- #first .widget-area -->
    <?php endif; ?>

    This is what I have on my page and nothing is displayed but when I view the source code for the page I see the following

    <p><?php if ( is_active_sidebar( 'homepage-newsfeed' ) ) : ?><br />
    <?php dynamic_sidebar( 'homepage-newsfeed' ); ?><br />
    <!-- #first .widget-area --><br />
    <?php endif; ?></p>

    Would it seem that the php isn't being processed?

  9. Carlos Moreira
    Member
    Posted 1 year ago #

    Are you putting it when you edit the page content?
    You have to put it in the template code. Appearance>Editor

  10. crookesa
    Member
    Posted 1 year ago #

    I had it in the page content that what must have been confusing me but I have placed it in the index.php template and the page.php template and it's still not appearing. I only want on my home page so was concentrating on index.php template.

    Thanks for the support

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.