Hallo zusammmen,
ich habe ein eigenes Widget im Enfoldtheme geschrieben. Im Adminbereich kann ich Werte ändern und dort klappt alles wunderbar. Wechsle ich auf die Seite, werden die Infos nicht angezeigt.
Ich habe a bissal rum gespielt und kann sagen, dass in der Function widget( $args, $instance ) $instance leer ist. Es war möglich alle Infos von $args anzuzeigen, dadurch bin ich mir sicher das ich an der richtigen Stelle bin, doch $instance ist leer.
PHP
class Matthias_Widget extends WP_Widget {
function __construct() {
$widget_ops = array(
'classname' => 'Matthias_Widget',
'description' => 'Widgetbeschreibung von mir',
);
parent::__construct( 'Matthias_Widget_123', 'Matthias_Widget', $widget_ops );
}
function widget( $args, $instance ) {
print_r($instance);
echo "<br>start<br>";
if ( ! empty( $instance['title'])){
echo $args['before_title'] .
apply_filters(
'widget_title',
$instance['title']
). $args['after_title'];
echo "1";
}
echo 'Hallo Matthias<br>';
if ( ! empty( $instance['bookings'])){
apply_filters(
'widget_bookings',
$instance['bookings']
). $args['after_title'];
echo "2";
}
echo 'Meine Bookingss';
}
function update( $new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['bookings'] = $new_instance['bookings'];
return $instance;
}
function form( $instance) {
$defaults = array( 'title' => 'Titel', 'bookings' => 'Titel2');
$instance = wp_parse_args( (array) $instance, $defaults);
?>
<p>
<lable
for="<?php echo $this->get_field_id( 'title') ?>">
Titel:
</lable>
</p>
<input id="<?php echo $this->get_field_id( 'title'); ?>"
name ="<?php echo $this->get_field_name( 'title'); ?>"
value ="<?php echo $instance['title']?>" />
<p>
<lable
for="<?php echo $this->get_field_id( 'bookings') ?>">
Bookings:
</lable>
</p>
<input id="<?php echo $this->get_field_id( 'bookings'); ?>"
name ="<?php echo $this->get_field_name( 'bookings'); ?>"
value ="<?php echo $instance['bookings']?>" />
<?php
}
}
Alles anzeigen