您可以创建一个小部件(Create a Widget) 像这样:
<?php /*
Plugin Name: WDG
Plugin URI:
Description: Plugin
Version: 0.1
Author URI:
*/
add_action( \'widgets_init\', \'my_wdg\' );
function my_wdg() {
register_widget( \'Wdg\' );
}
class Wdg extends WP_Widget {
function Wdg() {
/* Settings of widget */
$widget_ops = array( \'classname\' => \'Widget\', \'description\' => \' Plugin\' );
/* Control settings of widget */
$control_ops = array( \'width\' => 300, \'height\' => 350, \'id_base\' => \'wdg\' );
/* Create widget */
$this->WP_Widget( \'wdg\', \'Wdg\', $widget_ops, $control_ops );
}
function widget( $args, $instance ) {
extract( $args );
/* User-selected settings. */
$title = apply_filters(\'widget_title\', $instance[\'title\'] );
/* Before widget (theme defined). */
echo $before_widget;
/* Widget title (before e after theme defined). */
if ( $title )
echo $before_title . $title . $after_title;
echo\' <div id="recent">
<ul>\';
rewind_posts();
query_posts(\'posts_per_page=3\');
if ( have_posts() ) : while ( have_posts() ) : the_post();?>
<li>
<h5><a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
<?php the_title();?>
</a></h5>
<span>
<?php the_excerpt ?>
</span>
</li>
<?php endwhile; else: ?>
<p>I\'m sorry</p>
<?php endif; ?>
</ul>
</div>
<?php echo $after_widget; }
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
/* Strip tags modify qidget configuration. */
$instance[\'title\'] = strip_tags( $new_instance[\'title\'] );
return $instance;
}
function form( $instance ) {
/* default widget setting */
$defaults = array(
\'title\' => \'Recent Comments\',
);
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<p>
<label for="<?php echo $this->get_field_id( \'title\' ); ?>">Title:</label>
<input id="<?php echo $this->get_field_id( \'title\' ); ?>" name="<?php echo $this->get_field_name( \'title\' ); ?>" value="<?php echo $instance[\'title\']; ?>" style="width:100%;" />
</p>
<?php
}
} ?>
这个小部件可能会工作!