Hey guys, i created a plugin as you explained in your tutorial site. Everything work fine but i want to insert the widget also in my single-pages, which i only can add in the template files.
For my project, i need to update the single-event.php file and i tried to insert the plugin via the function the_widget().
<?php the_widget(‘Event_Widget’, $instance, $args); ?>
My $instance is an array and had all variables which i also match to the tpl via get_template_variables() function.
My array in the widget file:
return array(
‘headline’ => $instance[‘layout’][‘headline’],
‘headlineSize’ => $instance[‘layout’][‘headlineSize’],
‘body’ => $instance[‘layout’][‘body’],
‘txtPos’ => $instance[‘layout’][‘position’],
‘bgColor’ => $instance[‘layout’][‘bg_color’],
‘hl_color’ => $instance[‘layout’][‘hl_color’],
‘buttonTxt’ => $instance[‘button’][‘text’],
‘event’ => $instance[‘event’][‘category’],
‘layout’ => $instance[‘event’][‘layout’],
‘order’ => $instance[‘event’][‘order’],
);
So i create a $instance with …
$instance = array(
‘headline’ => ‘My Headline’,
‘headlineSize’ => ‘h2’,
‘body’ => ‘This is the Body’,
‘txtPos’ => ‘center’,
‘bgColor’ => ‘#FFF’,
‘hl_color’ => ‘#333’,
‘buttonTxt’ => ‘My Button’,
‘event’ => ‘festival’,
‘layout’ => 2,
‘order’ => ‘asc’,
);
At the end, i see the widget but nothing of my arguments was set to the widget. My widget come with the default settings.
How do i store the $var into my widget to get the output?
Thanks a lot for help!
Hi Aboutsam,
Data is passed to the widget in a similar manner as it’s structured in the widget itself. For example, if you want to pass the headline text, you’ll need to pass:
You’ll need to pass more than that for the widget to display, but the above example PHP should give you a better idea of how to proceed.