Wordpress Widget - Need to list Pages - wordpress

I have a wordpress widget where im saving the options, Title + Copy + URL
The url is generated by listing the wordpress pages
The below code saves and works fine on the front end. But in the widget settings panel when you save it reverts back to select page, i need it to display the previously selected item that it saved.
// Sidebar CTA Widget
class SidebarCTAWidget extends WP_Widget {
function SidebarCTAWidget() {
$widget_ops = array('classname' => 'SidebarCTAWidget', 'description' => 'Editable Sidebar CTAs' );
$this->WP_Widget('SidebarCTAWidget', 'Sidebar Call to Action', $widget_ops);
}
function form($instance) {
$defaults = array( 'title' => '', 'copy' => '', 'url' => '');
$instance = wp_parse_args( (array) $instance, $defaults );
$title = $instance['title'];
$copy = $instance['copy'];
$url = $instance['url'];
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>">Title:
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('copy'); ?>">Copy:
<textarea rows="5" class="widefat" name="<?php echo $this->get_field_name( 'copy' ); ?>" / ><?php echo esc_attr( $copy ); ?></textarea>
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id('url'); ?>">URL:
<select class="widefat" id="<?php echo $this->get_field_id('url'); ?>" name="<?php echo $this->get_field_name('url'); ?>" name="page-dropdown">
<option value=""> <?php echo esc_attr( __( 'Select Page' ) ); ?></option>
<?php
$pages = get_pages();
foreach ( $pages as $page ) {
$option = '<option value="' . get_page_link( $page->ID ) . '">';
$option .= $page->post_title;
$option .= '</option>';
echo $option;
}
?>
</select>
</label>
</p>
<?php }
//save the widget settings
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['copy'] = strip_tags( $new_instance['copy'] );
$instance['url'] = strip_tags( $new_instance['url'] );
return $instance;
}
function widget($args, $instance){
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
$copy = empty($instance['copy']) ? ' ' : apply_filters('widget_title', $instance['copy']);
$url = empty($instance['url']) ? ' ' : apply_filters('widget_title', $instance['url']);
if (!empty($title))
echo '<div class="clearfix sidebar-content"><h3>' . $title . '</h3>';
;
// This is the HTML
echo '<p>' . $copy . '</p></div>';
echo '<p class="sidebar-link">Find Out More</p>';
// END
echo $after_widget;
}
}
add_action( 'widgets_init', create_function('', 'return register_widget("SidebarCTAWidget");') );

Thanks to the help of #b__ i managed to work out how to compare the saved url in the database and mark it as selected
$option = '<option '. (get_page_link( $page->ID ) == attribute_escape($url) ? "selected='selected'":"").'value="' . get_page_link( $page->ID ) . '">';

Related

How to get searching result in categories wise in wordpress

I want to search any word and get the matched result as categories wise to show them under different categories in column . How to get the quire code for search page?
I suggest you to use this solution for category wise search.
class Category_Wise_Search_Widget extends WP_Widget {
/**
* Register widget with WordPress.
*/
public function __construct() {
parent::__construct(
'category_wise_search', // Base ID
'Category Wise Search', // Name
array( 'classname' => 'widget_search','description' => __( 'A search form for your site with category', 'text_domain' ), ) // Args
);
}
/**
* Front-end display of widget.
*
* #see WP_Widget::widget()
*
* #param array $args Widget arguments.
* #param array $instance Saved values from database.
*/
public function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$default_select_text = strip_tags($instance['default_select_text']);
if ( empty( $instance['default_select_text']))
$default_select_text = 'Any Category';
$show_count = ! empty( $instance['count'] ) ? '1' : '0';
$show_hierarchy = ! empty( $instance['show_hierarchy'] ) ? '1' : '0';
$default_cat = isset( $instance['default_cat'] ) ? absint( $instance['default_cat'] ) : 0;
$exclude = isset($instance['exclude'])?esc_attr($instance['exclude']):'';
$exclude_t = isset($instance['exclude_t'])?esc_attr($instance['exclude_t']):'';
if(isset($_GET['cat']))
$default_cat =absint($_GET['cat']);
$cat_args = array('selected'=>$default_cat,'show_count' => $show_count, 'hierarchical' => $show_hierarchy,'show_option_all'=>$default_select_text,'echo'=>0,'id'=>'searchform_cat','exclude'=>$exclude,'exclude_tree'=>$exclude_t,'orderby'=>'name','order' => 'asc');
?>
<?php echo $before_widget; ?>
<?php if ( $title ) echo $before_title . $title . $after_title; ?>
<?php
$form= '<form role="search" method="get" id="searchform" action="' . esc_url( home_url( '/' ) ) . '" >
<div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
'.wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args)).'
<input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
</div>
</form>';
echo apply_filters('get_search_form', $form);
?>
<?php echo $after_widget; ?>
<?php
// Reset the global $the_post as this query will have stomped on it
}
/**
* Sanitize widget form values as they are saved.
*
* #see WP_Widget::update()
*
* #param array $new_instance Values just sent to be saved.
* #param array $old_instance Previously saved values from database.
*
* #return array Updated safe values to be saved.
*/
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['default_select_text'] = strip_tags( $new_instance['default_select_text'] );
if($instance['default_select_text']=='')
$instance['default_select_text'] = 'Any Category';
$instance['default_cat'] = ($new_instance['default_cat']);
$instance['count'] = !empty($new_instance['count']) ? 1 : 0;
$instance['show_hierarchy'] = !empty($new_instance['show_hierarchy']) ? 1 : 0;
$instance['exclude'] = strip_tags($new_instance['exclude']);
$instance['exclude_t'] = strip_tags($new_instance['exclude_t']);
return $instance;
}
/**
* Back-end widget form.
*
* #see WP_Widget::form()
*
* #param array $instance Previously saved values from database.
*/
public function form( $instance ) {
$title = $instance['title'];
if ( isset( $instance[ 'default_select_text' ] ) ) {
$default_select_text = $instance[ 'default_select_text' ];
}
else {
$default_select_text = __( 'Any Category', 'text_domain' );
}
$count = isset($instance['count']) ? (bool) $instance['count'] :false;
$show_hierarchy = isset( $instance['show_hierarchy'] ) ? (bool) $instance['show_hierarchy'] : true;
$default_cat = isset($instance['default_cat'] ) ? absint($instance['default_cat']) : 0;
$exclude = isset($instance['exclude'] ) ? strip_tags($instance['exclude']) : '';
$exclude_t = isset($instance['exclude_t'] ) ? strip_tags($instance['exclude_t']) : '';
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'default_select_text' ); ?>"><?php _e( 'Default select box text:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'default_select_text' ); ?>" name="<?php echo $this->get_field_name( 'default_select_text' ); ?>" type="text" value="<?php echo esc_attr( $default_select_text); ?>" />
</p>
<p><label for="<?php echo $this->get_field_id('exclude'); ?>"><?php _e( 'Exclude Categories :' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('exclude'); ?>" name="<?php echo $this->get_field_name('exclude'); ?>" type="text" value="<?php echo $exclude; ?>" />
<br>Enter a comma seperated category ID.<br>ex : <code>2,3</code> (This widget will display all of your categories except these categories).
</p>
<p><label for="<?php echo $this->get_field_id('exclude_t'); ?>"><?php _e( 'Exclude Categories With Childs :' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('exclude_t'); ?>" name="<?php echo $this->get_field_name('exclude_t'); ?>" type="text" value="<?php echo $exclude_t; ?>" />
<br>Enter a comma seperated category ID.<br>ex : <code>1,4</code> (This widget will display all of your categories except these categories and its childs).
</p>
<p>
<label for="<?php echo $this->get_field_id( 'default_cat' ); ?>"><?php _e( 'Default select category :' ); ?></label>
<?php $cat_arg = array( 'hierarchical' => 1,'selected'=>$default_cat,'show_option_all'=>($default_select_text!='')?esc_attr( $default_select_text):esc_attr( $default_select_text),'echo'=>0,'id'=>$this->get_field_id( 'default_cat' ),'name'=>$this->get_field_name( 'default_cat' ),'exclude'=>$exclude,'class'=>'widefat');
echo wp_dropdown_categories($cat_arg);?>
</p>
<p>
<input class="checkbox" type="checkbox" <?php checked( $show_hierarchy ); ?> id="<?php echo $this->get_field_id( 'show_hierarchy' ); ?>" name="<?php echo $this->get_field_name( 'show_hierarchy' ); ?>" />
<label for="<?php echo $this->get_field_id( 'show_hierarchy' ); ?>"><?php _e( 'Show hierarchy' ); ?></label><br />
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>"<?php checked( $count ); ?> />
<label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
</p>
<?php
}
} // class Category_Wise_Search
// register Category_Wise_Search_Widget widget
add_action( 'widgets_init', create_function( '', 'register_widget( "Category_Wise_Search_Widget" );' ) );
register_deactivation_hook(__FILE__, 'shambhu_plugin_deactivate');
function shambhu_plugin_deactivate ()
{
unregister_widget('Category_Wise_Search_Widget');
}

How to create WordPress widget using custom menu select

I'm creating a custom widget for WordPress but am wanting to use the same select menu as the default Custom Menu widget does. So far what I have works except the selected menu isn't being saved or displayed on the frontend. Any help or direction with this is appreciated. Thanks.
For brevity, I've removed extra widget options, so this is basically going to look very close to the Custom Menu widget:
class kedc_mini_sitemap extends WP_Widget {
/*constructor*/
function kedc_mini_sitemap() {
parent::WP_Widget(false, $name = 'Mini Sitemap');
}
/**/
function widget($args, $instance) {
extract( $args );
// widget options
$title = apply_filters('widget_title', $instance['title']);
$nav_menu1 = ! empty( $instance['nav_menu'] ) ? wp_get_nav_menu_object( $instance['nav_menu'] ) : false;
$checkbox = $instance['checkbox'];
echo $before_widget;
if ($title) {
echo $before_title . $title . $after_title;
}
if ($nav_menu1) {
echo wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu1 ) );
}
if ($checkbox == true) {
echo 'This message is displayed if our checkbox is checked.';
}
echo $after_widget;
}
/* saves options chosen from the widgets panel */
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['nav_menu'] = (int) $new_instance['nav_menu'];
$instance['checkbox'] = strip_tags($new_instance['checkbox']);
return $instance;
}
/* display widget in widgets panel */
function form($instance) {
$title = esc_attr($instance['title']);
$nav_menu1 = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
$checkbox = esc_attr($instance['checkbox']);
$menus1 = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
?>
<p>
<label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
<select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
<?php
foreach ( $menus1 as $menu1 ) {
echo '<option value="' . $menu1->term_id . '"'
. selected( $nav_menu, $menu1->term_id, false )
. '>'. $menu1->name . '</option>';
}
?>
</select>
</p>
<p>
<input id="<?php echo $this->get_field_id('checkbox'); ?>" name="<?php echo $this->get_field_name('checkbox'); ?>" type="checkbox" value="1" <?php checked( '1', $checkbox ); ?>/>
<label for="<?php echo $this->get_field_id('checkbox'); ?>"><?php _e('Do you want this to display as 2 columns?'); ?></label>
</p>
<?php
}
}
// register widget
add_action('widgets_init', create_function('', 'return register_widget("kedc_mini_sitemap");'));
You have a typo in the form() function: $nav_menu1 and $nav_menu.
Use more meaningful, strict and descriptive names for your variables. For example, $menus1 could be called $get_nav_menus.
Use a good IDE, like NetBeans or similar, and check the WordPress Coding Standards Handbook.
Oh, yes, your code is dumping PHP Notices, always develop with WP_DEBUG enabled.

Wordpress Custom Widget Select Options Not Saving

I'm very new to coding Wordpress plugins/widgets (this is my first time!). I've built a very basic Wordpress plugin which consists of 2 text inputs and a select field. The text inputs work fine however the select box doesn't appear to be saving when I hit the "Save" button.
Here is my plugin code:
<?php
/* Plugin Name: Sidebar Box
Plugin URI: http://www.website.com
Description: Displays contact box in sidebar
Version: 1.0
Author: JM
Author URI: N/A
*/
// use widgets_init action hook to execute custom function
add_action( 'widgets_init', 'jm_box_widget' );
//register our widget
function jm_box_widget() {
register_widget( 'jm_box_widget_my_info' );
}
//boj_widget_my_info class
class jm_box_widget_my_info extends WP_Widget {
//process the new widget
function jm_box_widget_my_info() {
$widget_ops = array(
'classname' => 'jm_box_widget_class',
'description' => 'Sidebar Box Widget.'
);
$this->WP_Widget( 'jm_box_widget_my_info', 'Box Widget', $widget_ops );
}
//build the widget settings form
function form($instance) {
$defaults = array( 'title' => 'Box Page Widget', 'description' => '', 'boxtype' => '' );
$instance = wp_parse_args( (array) $instance, $defaults );
$title = $instance['title'];
$description = $instance['description'];
$boxtype = $instance['boxtype'];
?>
<p>Title: <input class="widefat" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /></p>
<p>Description: <textarea class="widefat" name="<?php echo $this->get_field_name( 'description' ); ?>" / ><?php echo esc_attr( $description ); ?></textarea></p>
<p>Sex:
<select id="<?php echo $this->get_field_id( 'boxtype' ); ?>" name="<?php echo $this->get_field_name( 'boxtype' ); ?>" class="widefat" style="width:100%;">
<option <?php if ( 'box1' == $instance['format'] ) echo 'selected="selected"'; ?> value="box1">box1</option>
<option <?php if ( 'box2' == $instance['format'] ) echo 'selected="selected"'; ?> value="box2">box2</option>
</select>
</p>
<?php
}
//save the widget settings
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['description'] = strip_tags( $new_instance['description'] );
$instance['boxtype'] = ( $new_instance['boxtype'] );
return $instance;
}
//display the widget
function widget($args, $instance) {
extract($args);
echo $before_widget;
$title = apply_filters( 'widget_title', $instance['title'] );
$description = empty( $instance['description'] ) ? ' ' : $instance['description'];
$boxtype = empty( $instance['boxtype'] ) ? ' ' : $instance['boxtype'];
echo '<div class="sidebar-box" id="' . $boxtype . '" onmouseover="this.style.cursor=\'pointer\'" onmouseup="window.location=\'' . $boxtype . '\'">
<h3>' . $title . '</h3>
<p>' . $description . '</p>
</div>';
echo $after_widget;
}
}
?>
I can't for the life of me workout why it's not saving.
Any help would be greatly appreciated.
Thanks,
James
Somewhere along the line you must have changed $instance['format'] to $instance['boxtype'] but not in the form. The options need changing.
<option <?php if ('box1' == $boxtype )

Override widget in function WordPress

Im trying to override the text widget in WordPress. My code looks like this:
class WP_Widget_Text_Custom extends WP_Widget {
function __construct() {
$widget_ops = array('classname' => 'widget_text', 'description' => __('Arbitrary text or HTML'));
$control_ops = array('width' => 400, 'height' => 350);
parent::__construct('text', __('Text'), $widget_ops, $control_ops);
}
function WP_Widget_Calendar( $args, $instance ) {
extract($args);
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
$text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
echo $before_widget;
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
<div class="textwidget test"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
<?php
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
if ( current_user_can('unfiltered_html') )
$instance['text'] = $new_instance['text'];
else
$instance['text'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['text']) ) ); // wp_filter_post_kses() expects slashed
$instance['filter'] = isset($new_instance['filter']);
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
$title = strip_tags($instance['title']);
$text = esc_textarea($instance['text']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p>
<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
<p><input id="<?php echo $this->get_field_id('filter'); ?>" name="<?php echo $this->get_field_name('filter'); ?>" type="checkbox" <?php checked(isset($instance['filter']) ? $instance['filter'] : 0); ?> /> <label for="<?php echo $this->get_field_id('filter'); ?>"><?php _e('Automatically add paragraphs'); ?></label></p>
<?php
}
}
function custom_register_widgets() {
register_widget( 'WP_Widget_Text_Custom' );
}
add_action( 'widgets_init', 'custom_register_widgets' );
Im getting the following error message:
*function WP_Widget::widget() must be over-ridden in a sub-class.*
I have copied the WP_Widget_Text from default-widgets.php to functions.php and added _Custom in class name.
Why am I getting this error and how do I fix it?
You might try changing WP_Widget_Calendar to be widget.

Parse error with theme wordpress

I've developed a local site with wordpress and the theme Lugada.
All is OK on local. I've transfered all data on ovh.
When I want to see what is done I get the error:
Parse error: syntax error, unexpected T_STRING in
/homez.705/cadeauxd/www/wp-content/themes/lugada/include/widget.php on
line 1
When I add empty rows at the beginning it's the same thing: on line 1
Here's the file :
<?php
class RecentPost_Widget extends WP_Widget {
/* Register widget with WordPress. */
public function __construct() {
parent::__construct(
'recentpost_widget', // Base ID
'(Lugada) Recent Post with Thumbnail', // Name
array( 'description' => __( 'lugada recent post with post-thumbnail support widget.', 'lugada' ), ) // Args
);
}
/* Front-end display of widget. */
public function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$rcnumber = $instance['rcnumber'] ;
echo $before_widget;
if ( ! empty( $title ) )
echo $before_title . $title . $after_title;
?>
<?php
echo '<ul>';
echo lugada_display_recent_posts($rcnumber);
echo '</ul>';?>
<?php
echo $after_widget;
}
/* Sanitize widget form values as they are saved. */
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['rcnumber'] = strip_tags( $new_instance['rcnumber'] );
return $instance;
}
/* Back-end widget form. */
public function form( $instance ) {
if ( $instance ) {
$title = esc_attr( $instance[ 'title' ] );
$rcnumber = esc_attr( $instance[ 'rcnumber' ] );
}
else {
$title = __( 'Recent post', 'lugada' );
$rcnumber = __( '5', 'lugada' );
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:','lugada' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'rcnumber' ); ?>"><?php _e( 'Number of recent post to show:','lugada' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'rcnumber' ); ?>" name="<?php echo $this->get_field_name( 'rcnumber' ); ?>" type="text" value="<?php echo $rcnumber; ?>" />
</p>
<?php
}
} // class RecentPost_Widget
class RandomPost_Widget extends WP_Widget {
/* Register widget with WordPress. */
public function __construct() {
parent::__construct(
'randompost_widget', // Base ID
'(Lugada) Random Post', // Name
array( 'description' => __( 'lugada random post widget.', 'lugada' ), ) // Args
);
}
/* Front-end display of widget. */
public function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
$rndnumber = $instance['rndnumber'] ;
echo $before_widget;
if ( ! empty( $title ) )
echo $before_title . $title . $after_title;
?>
<?php
echo '<ul>';
echo lugada_display_random_posts($rndnumber);
echo '</ul>';?>
<?php
echo $after_widget;
}
/* Sanitize widget form values as they are saved. */
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['rndnumber'] = strip_tags( $new_instance['rndnumber'] );
return $instance;
}
/* Back-end widget form. */
public function form( $instance ) {
if ( $instance ) {
$title = esc_attr( $instance[ 'title' ] );
$rndnumber = esc_attr( $instance[ 'rndnumber' ] );
}
else {
$title = __( 'Random post', 'lugada' );
$rndnumber = __( '5', 'lugada' );
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:','lugada' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'rndnumber' ); ?>"><?php _e( 'Number of random post to show:','lugada' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'rndnumber' ); ?>" name="<?php echo $this->get_field_name( 'rndnumber' ); ?>" type="text" value="<?php echo $rndnumber; ?>" />
</p>
<?php
}
} // class RandomPost_Widget
?>
That error usually means that you've got an unclosed string somewhere; the stated line number is usually not meaningful. Also check for things like unpaired parentheses or brackets, and places where you think you're writing in either HTML or PHP but you're actually writing in the other one.

Resources