就我个人而言,我不知道如何让这个小部件(内置在主题中)显示摘录而不是帖子内容。你们能帮我看看吗。任何帮助都将不胜感激。
// =============================== Latest news posts Widget (particular category) ======================================
class latest_post1 extends WP_Widget {
function latest_post1() {
//Constructor
$widget_ops = array(\'classname\' => \'widget Latest News\', \'description\' => \'List of latest posts in particular category\' );
$this->WP_Widget(\'latest_post1\', \'PT → Latest News\', $widget_ops);
}
function widget($args, $instance) {
// prints the widget
extract($args, EXTR_SKIP);
echo $before_widget;
$title = empty($instance[\'title\']) ? \'\' : apply_filters(\'widget_title\', $instance[\'title\']);
$category = empty($instance[\'category\']) ? \' \' : apply_filters(\'widget_category\', $instance[\'category\']);
$post_number = empty($instance[\'post_number\']) ? \' \' : apply_filters(\'widget_post_number\', $instance[\'post_number\']);
$post_link = empty($instance[\'post_link\']) ? \' \' : apply_filters(\'widget_post_link\', $instance[\'post_link\']);
// if ( !empty( $title ) ) { echo $before_title . $title . $after_title; };
echo \'\';
?>
<?php if($title){?>
<h3><?php echo $title; ?></h3>
<?php } ?>
<div class="latestpost">
<?php
global $post;
$latest_menus = get_posts(\'numberposts=\'.$post_number.\'postlink=\'.$post_link.\'&category=\'.$category.\'\');
foreach($latest_menus as $post) :
setup_postdata($post);
?>
<?php $post_images = bdw_get_images($post->ID,\'large\');?>
<div class="post_list">
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<cite>By <?php the_author_posts_link(); ?></cite>
<div class="date"> <?php the_time(\'jS F\') ?></div>
</div>
<?php endforeach; ?>
<?php
echo \' </div>\';
echo $after_widget;
}
function update($new_instance, $old_instance) {
//save the widget
$instance = $old_instance;
$instance[\'title\'] = strip_tags($new_instance[\'title\']);
$instance[\'category\'] = strip_tags($new_instance[\'category\']);
$instance[\'post_number\'] = strip_tags($new_instance[\'post_number\']);
$instance[\'post_link\'] = strip_tags($new_instance[\'post_link\']);
return $instance;
}
function form($instance) {
//widgetform in backend
$instance = wp_parse_args( (array) $instance, array( \'title\' => \'\', \'category\' => \'\', \'post_number\' => \'\' ) );
$title = strip_tags($instance[\'title\']);
$category = strip_tags($instance[\'category\']);
$post_number = strip_tags($instance[\'post_number\']);
$post_link = strip_tags($instance[\'post_link\']);
?>
<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(\'category\'); ?>">Categories (<code>IDs</code> separated by commas):
<input class="widefat" id="<?php echo $this->get_field_id(\'category\'); ?>" name="<?php echo $this->get_field_name(\'category\'); ?>" type="text" value="<?php echo attribute_escape($category); ?>" />
</label>
</p>
<p>
<label for="<?php echo $this->get_field_id(\'post_number\'); ?>">Number of posts:
<input class="widefat" id="<?php echo $this->get_field_id(\'post_number\'); ?>" name="<?php echo $this->get_field_name(\'post_number\'); ?>" type="text" value="<?php echo attribute_escape($post_number); ?>" />
</label>
</p>
<?php
}
}
register_widget(\'latest_post1\');