wordpress 在 plugin 里定义一个 widget
来源:互联网 发布:淘宝商城专业托管 编辑:程序博客网 时间:2024/05/21 09:15
因为在加载plugin的时候,还没有完全加载完wordpress,导致 global $wp_widget_factory 为 NULL, 所以需要如下方式解决:
add_action('widgets_init', 'F_Home_Video');function F_Home_Video(){register_widget('F_Home_Video_Widget');}class F_Home_Video_Widget extends WP_Widget {function F_Home_Video_Widget() {parent::WP_Widget(false, $name = 'Home video widget');}function widget($args, $instance) {extract( $args );global $wpdb;$count = $instance['count'];$r = array('numberposts' => $count, 'category' => 3,'orderby' => 'post_date','order' => 'DESC', 'post_type' => 'post',);$posts = get_posts($r);if( empty($posts) ) return; ?> <?php echo $before_widget; ?> <?php echo $before_title . apply_filters('the_title', $instance['title']) . $after_title; ?><ul class="flowwidgets"><?phpforeach($posts as $post){setup_postdata($post);$attachment_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );$url = $attachment_url['0'];echo '<li><a><img src="'.$url.'" /></a><h2>'.get_the_title($post->ID).'</h2>'.the_content($post->ID).'</li>';}?></ul> <?php echo $after_widget; ?> <?php}function update($new_instance, $old_instance) {return $new_instance;}function form($instance) {$title = esc_attr($instance['title']);$count = esc_attr($instance['count']); ?> <p><label for="<?php echo $this->get_field_id('count'); ?>"><?php _e('Display Number:'); ?><input class="widefat" id="<?php echo $this->get_field_id('count'); ?>" name="<?php echo $this->get_field_name('count'); ?>" type="text" value="<?php echo $count; ?>" /></label></p> <?php }}
- wordpress 在 plugin 里定义一个 widget
- 在一个div里单独定义超链接的样式…
- 显示Dashboard里的widget在桌面上
- Wordpress学习制作Widget
- 在jsp里定义函数
- 在nodejs里定义全局变量
- 创建wordpress plugin
- Cosmos上增加一个新的widget到widget selector page里
- 在Widget里获取系统时间改变的广播
- 在widget里更新图片的一些经验
- 如何在一个站点里定义多个sitemap---针对asp.net2.0
- 我在一个结构体里定义超过两个字符数..
- 一个WordPress在XAMPP下的问题
- GD Star Rating的widget停留在 loading...或a WordPress rating system
- 遇到的问题-----------定义一个全局变量,在page_load里赋值,但在其他按钮中调用仍为空
- 定义不一定在相应的cpp里
- MEDIASUBTYPE_MPEG2_TRANSPORT在哪个文件里被定义?
- 宏定义放在结构体里
- 交织编码
- HDU 1403 Longest Common Substring
- poj1251 hdu 1301 Jungle Roads
- Sender的认识
- linux下防止文件误删的办法
- wordpress 在 plugin 里定义一个 widget
- 浅谈WebKit之Port篇
- 【Android UI设计与开发】第04期:引导界面(四)仿人人网V5.9.2最新版引导界面
- Elevator 杭电1008
- 熟悉 和使用 jar 文件
- 开发者须知 HTML5 的15个新特性
- 期中考试2
- Android 基于ImageSwitcher实现的左右切换图片
- Cocos2d-x 帧动画