Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6645449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:17:20+00:00 2026-05-26T00:17:20+00:00

I have created a widget and so far it only displays on the home

  • 0

I have created a widget and so far it only displays on the home page. However I want it to appear on the post page, and only if the user has inputted a parameter.

class My_Widget extends WP_Widget {
    function __construct() {
        $widget_ops = array ('description' => __ ( 'Lorem ipsum' ) );
        parent::__construct ( 'exampl', __ ( 'Example' ), $widget_ops );
    }
    function widget($args, $instance) {
        extract ( $args );
        $title = apply_filters ( 'widget_title', empty ( $instance ['title'] ) ? ' ' : $instance ['title'] );
        # Before the widget
        echo $before_widget;

        # The title
        if ($title)
            echo $before_title . $title . $after_title;

        # Make the Hello World Example widget
        echo isset($instance['foo'])?$instance['foo']:'foo';
        echo isset($instance['bar'])?$instance['bar']:'bar';

        # After the widget
        echo $after_widget;

    }
    //The global widget options
    function form($instance){
        /* Set up some default widget settings. */
        $defaults = array( 'foo' => 'oof', 'bar' => 'rab');
        $instance = wp_parse_args( (array) $instance, $defaults ); ?>
        <p>
            <label for="<?php echo $this->get_field_id( 'foo' ); ?>"><!--shortened... -->
        </p>
        <?php 
    }
}

function my_init() {
    register_widget ( 'My_Widget' );
}
add_action ( "widgets_init", "my_init" );

Now the widget appears in the home page on the right, the default options are treated correctly.

It does not appear on the post page however. (“Hello world! Welcome to WordPress. This is your first post…”)
A) How can I make it appear only on the post page
B) How can I control the parameters on a per post level

Example: The global setting “color” should be ‘green’, controlled on the widgets page. however in the post page I want a textarea “poemoftheday”, if it’s not empty it should show up on the sidebar using the global “color” ‘green’, but depending on the post, the “poemoftheday” will be different or not present

My Problems All the WordPress terms and version have made it really hard to find out the correct current solution. I’ve been working on this for 7 hours now and I’m really stuck. Not asking people to code for me, but I need to know the right terms and methods I should be using. Pointers to tutorials/documentations that solve fit my requirements greatly appreciated (there are sooo many tutorials, but they all behave different from the behaviour I’m looking for)

Visually
This is where the global configuration is, great
^This is where the global configuration is, great


This is where I'd like to have the per post configuration
^This is where I’d like to have the per post configuration


This is where it's appearing right now, no good
^This is where it’s appearing right now – displaying good, position no good


This is where I'd like it to appear
^This is where I’d like it to appear

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:17:21+00:00Added an answer on May 26, 2026 at 12:17 am

    So here’s how I solved it after 5 days.

    To write store per_post vars I had to use the function

    • In my class constructor i added the hook add_action ( 'add_my_meta_box', array (__CLASS__, 'add_my_meta_box') );
    • create the callback function add_my_meta_box($page) in my class
    • In that callback amongst other things add_meta_box ( 'My Widget', 'My box', array (__CLASS__, 'render_meta_box' ), $page);

    All values are read and stored with global $post; and the wordpress functions get_post_meta ($post->ID, 'my_var',true ) and update_post_meta ($post->ID, 'my_var', $value )

    To make sure that my widget only appears on a single post page I used the check
    if(is_single()) before echoing the widget

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have created a custom post type named Books & i have a widget
I have created a widget in my application , now when a widget is
I have created an App Widget for Android 1.5. It uses a TextView to
I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in
I have created a widget kind of. In reality I put the information in
I have created models and from the models, I created ModelForms . However, I
I want to create a pagination script using jquery UI's slider widget. So far
The organization I work for has created a small flash widget that we're encouraging
I want to download a file from the internet. And so far I have
I have a system which has certain page content stored in the database. Within

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.