I have built a custom widget with this code:
class rfw_dock extends WP_Widget {
function __construct() {
parent::__construct('rfw_dock', __('TITLE'), array( 'description' => __( 'DESCRIPTION')));
}
function widget($args, $instance) {
$title = $instance['title'];
$rss_url = $instance['rss_url'];
$rss = fetch_feed($rss_url);
$rss_items = $rss->get_items( 0, 1 );
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
foreach ($rss_items as $item) {
echo '

';
echo $after_widget;
}
}
function form($instance) {
$title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
$rss_url = isset( $instance['rss_url'] ) ? esc_attr( $instance['rss_url'] ) : '';
$number = isset( $instance['number'] ) ? absint( $instance['number'] ) : 6; ?>

<label for="get_field_id( 'title' ); ?>">
<input class="widefat" id="get_field_id( 'title' ); ?>" name="get_field_name( 'title' ); ?>" type="text" value="" />

<label for="get_field_id( 'rss_url' ); ?>">
<input class="widefat" id="get_field_id( 'rss_url' ); ?>" name="get_field_name( 'rss_url' ); ?>" type="text" value="" />

<?php
}
function update($new_instance, $old_instance) {
$instance = array();
$instance['title'] = strip_tags($new_instance['title']);
$instance['rss_url'] = strip_tags($new_instance['rss_url']);
$instance['number'] = (int) $new_instance['number'];
$instance['show_feed_title'] = ($new_instance['show_feed_title']==true);
$instance['feed_words'] = (int) $new_instance['feed_words'];
$instance['content_display'] = strip_tags($new_instance['content_display']);
return $instance;
}
}
register_widget('rfw_dock');

And registered this sidebar:
register_sidebar( array(
'name' => __('Søstersider'),
'before_widget' => '

',
'after_widget' => '

',
'before_title' => '

',
'after_title' => '

'
) );

Pretty straight-forward, right? Well, my problem is that the $before_title, $after_title, $before_widget and $after_widget doesn’t return anything, even though they’re specified in the code. Isn’t those variables how you’re supposed to define the information in the register_sidebar? At least, it is in default-widgets.php.

I’m sorry, but I’m not the best in PHP, although I consider myself to have a medium-levelled knowledge in it. I’ve tried a lot before posting this, but nothing works. Can someone please help me out? Thanks.

(By the way, I can’t figure out how to get a block code. 4 spaces does not work!)

Read more here: $before/after_widget/title not displaying anything


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

,

Wordpress related questions and answers: