这是我的插件代码。该文件位于插件文件夹中。我在这里保存一些数据:
<?php
/*
Plugin Name: Losninger
Plugin URL: http://yyy.no
Description: Show losninger
Version: 1.0
Author: xxx - zzz zzz
Author URI: http://asd.com
Contributors:
*/
/*
* Register losninger
*
*/
class losninger extends WP_Widget {
public function __construct(){
$widget_ops = array(
'classname' => 'losninger',
'description' => 'show losninger'
);
$this->WP_Widget(
'losninger',
'Losninger',
$widget_ops
);
add_action( 'init', array( $this, 'losninger_setup_post_types' ) );
add_action('widgets_init',create_function('','return register_widget("losninger");'));
add_action('init', 'losninger_setup_post_types');
wp_enqueue_style( 'losninger-Styles', plugin_dir_url( __FILE__ ) . 'losninger.css', array(), '0.1', 'screen' );
}
function widget($args, $instance) { // widget sidebar output
extract($args, EXTR_SKIP);
echo $before_widget; // pre-widget code from theme
$this->getLosninger();
echo $after_widget; // post-widget code from theme
}
public function losninger_setup_post_types() {
$losninger_labels = apply_filters( 'losninger_labels', array(
'name' => 'Losninger',
'singular_name' => 'Losninger',
'add_new' => __('Add New', 'losninger'),
'add_new_item' => __('Add New losninger', 'losninger'),
'edit_item' => __('Edit losninger', 'losninger'),
'new_item' => __('New losninger', 'losninger'),
'all_items' => __('All losninger', 'losninger'),
'view_item' => __('View losninger', 'losninger'),
'search_items' => __('Search losninger', 'losninger'),
'not_found' => __('No losninger found', 'losninger'),
'not_found_in_trash' => __('No losninger found in Trash', 'losninger'),
'parent_item_colon' => '',
'menu_name' => __('Losninger', 'losninger'),
'exclude_from_search' => true
));
$losninger_args = array(
'labels' => $losninger_labels,
'public' => true,
'publicly_queryable'=> true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'capability_type' => 'post',
'has_archive' => false,
'hierarchical' => false,
'supports' => apply_filters('losninger_supports', array( 'title', 'editor' ) ),
);
register_post_type( 'losninger', apply_filters( 'losninger_post_type_args', $losninger_args ) );
}
function getLosninger(){
ob_start();
// Create the Query
$post_type = 'losninger';
$orderby = 'menu_order';
$order = 'ASC';
$posts_per_page = 50;
$query = new WP_Query( array (
'post_type' => $post_type,
'posts_per_page' => $posts_per_page,
'orderby' => $orderby,
'order' => $order,
'no_found_rows' => 1
)
);
//Get post type count
$post_count = $query->post_count;
$i = 1;
// Displays FAQ info
if( $post_count > 0) :
// Loop
echo '<section id="losningerSection"><div class="losningerSectionInner">';
while ($query->have_posts()) : $query->the_post();
?>
<div class="losninger">
<h3 class="losninger_title"><?php the_title(); ?></h3>
<p id="losninger_<?php echo get_the_ID(); ?>"><?php echo get_the_content(); ?></p>
</div>
<?php
$i++;
endwhile;
echo '</div></section>';
endif;
// Reset query to prevent conflicts
wp_reset_query();
}
}
我怎样才能得到这个插件作为一个小部件?我想在一个页面中显示这个小部件,该页面将显示数据(我保存在管理员的插件中)。
注意:由于某种原因,我没有得到这个插件的管理部分(左侧菜单)。我确定我在这里做错了什么。谁能帮我解决这个问题?