1

In functions.php I added this code.

function page_widget_init( $post_id = 0 ) { {
    register_sidebar( array(
        'name' => __( 'Page Widgets', 'seven_theme' ),
        'id' => 'page-widgets-' . $post_id,
        'description' => __( 'To display Layers Widgets in front page, before your posts, after header.', 'seven_theme' ),
    ) );    
}
add_action( 'widgets_init', 'page_widget_init', 100 );

First how to get post id in functions.php register_sidebar **$post_id**

Now going to page template which i created using page.php, called Blog Template

Call this widget in this page.

dynamic_sidebar( 'page-widgets-' . $post->ID );

My idea is to create unique widget content using post ID.

  • Hi, anyone thinking about this widget type? – inkcolor Aug 25 '16 at 15:47
0

In your code you are trying to register a different sidebar for every post. Now, that would be possible (though with slightly different code), but it would mean that if you have, say, a hundred posts, you would have hundred widget areas in your admin, all of which you would have to fill with different widgets that have their own content.

I don't know what exactly you are trying to achieve, but if you want to pull information from specific posts in a sidebar, you probably want to build a widget. You can still have unique information on every page, but not a cluttered widget dashboard.

I can think of more complicated setups, but you would have to provide more detail on what you are trying to achieve.

  • Yes that is right i am trying to do the same, but not for post, adding it to pages. Looking for dynamic widget area with unique content in each pages. – inkcolor Aug 23 '16 at 8:56
  • @inkcolor That would mean you need a different sidebar for pages only. Or a widget that only displays content on a page. – cjbj Aug 23 '16 at 8:59
  • Yes that would be for pages only. And i will call it in pages.php or pages templates. – inkcolor Aug 24 '16 at 7:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.