Jump to content
  • 0

Гуру WP помогите


Mr.Black
 Share

Question

Здравствуйте, захотелось виджетировать свою тему, и столкнулся с проблем. Виджет не работает, где то ошибка в коде. Кто сможет помочь?

Код

<?php
/*
Plugin Name: Random Post Widget
Plugin URI: http://jamesbruce.me/
Description: Random Post Widget grabs a random post and the associated thumbnail to display on your sidebar
Author: James Bruce
Version: 1
Author URI: http://jamesbruce.me/
*/


class RandomPostWidget extends WP_Widget
{
function __construct()
{
$widget_ops = array('description' => __('Arbitrary text or HTML'));
$control_ops = array('width' => 400, 'height' => 350);
parent::__construct('About Me', __('About Me'), $widget_ops, $control_ops);
}


function form($instance)
{
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'image' => '', 'text' => '' ) );
$title = strip_tags($instance['title']);
$image = $instance['image'];
$text = $instance['text'];
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('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('image'); ?>"><?php _e('Image url:'); ?> <input class="widefat" id="<?php echo $this->get_field_id('image'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($image); ?>" /></label></p>
<p><label for="<?php echo $this->get_field_id('text'); ?>"><?php _e('Text (You can use HTML tag):'); ?><textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>" ></textarea></label></p>
<?php
}

function update($new_instance, $old_instance)
{
$instance = $old_instance;
$instance['title'] = $new_instance['title'];
$instance['image'] = $new_instance['image'];
$instance['text'] = $new_instance['text'];
return $instance;
}

function widget($args, $instance)
{
extract($args, EXTR_SKIP);

echo '<aside class="aboutMe" >';
$title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
$image = empty($instance['image']) ? ' ' : apply_filters('widget_title', $instance['image']);
$text = empty($instance['text']) ? ' ' : apply_filters('widget_title', $instance['text']);

if (!empty($title))
echo '<h5>' . $title . '</h5>';

// WIDGET CODE GOES HERE
echo '<img src="'. $image.'" alt="" />';
echo '<p>'.$text.'</p>';
echo '</aside>';
}

}
add_action( 'widgets_init', create_function('', 'return register_widget("RandomPostWidget");') );?>

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Где то ошибка в коде, все работало, но потом я что то изменил, и уже не работает. Ввожу данные в админке а они не появляются, появляется только бекграунд виджета

Так переустанови виджет

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy