网站开发的关键技术与难点,上海做网站站优云一一十七,wordpress添加新页面跳转,制作企业网站多少钱wordpress 焦点图插件-增删改查操作 2012-02-01 15:39:14分类#xff1a; 系统运维 该插件在wordpress-3.3.1-zh_CN版本下开发#xff0c;主要用于在后台管理首页焦点图#xff08;图片轮播#xff09;。存放焦点图信息的表 focusphoto(id,photourl,linkto,title,descripti…wordpress 焦点图插件-增删改查操作 2012-02-01 15:39:14 分类 系统运维 该插件在wordpress-3.3.1-zh_CN版本下开发主要用于在后台管理首页焦点图图片轮播。存放焦点图信息的表 focusphoto(id,photourl,linkto,title,description)该插件包括2个文件 focusphoto.php和focusphoto-admin.php效果如图具体代码如下focusphoto.php 包含以下函数focusphoto_install() 创建表focusphoto(id,photourl,linkto,title,description)focusphoto_uninstall() 删除表editfocusphoto_menu() focusphoto_admin_actions() 在后台添加“设置》焦点图管理”导航链接 ?php/*Plugin Name: 焦点图插件Plugin URI: http://hzm.blog.chinaunix.netDescription: 该插件在wordpress-3.3.1-zh_CN版本下开发主要用于在后台管理首页焦点图图片轮播Author: Henry PoterVersion: 1.0Author URI: http://hzm.blog.chinaunix.net*/ register_activation_hook(__FILE__ , focusphoto_install );register_deactivation_hook(__FILE__ , focusphoto_uninstall);function focusphoto_install() { global $wpdb; $table $wpdb-prefix . focusphoto; $sql create table $table( id int auto_increment primary key, photourl varchar(200), linkto varchar(200), title varchar(255), description varchar(1000) ) CHARSETUTF8; $wpdb-query($sql);}function focusphoto_uninstall(){ global $wpdb; $table $wpdb-prefix . focusphoto; $sql drop table $table; $wpdb-query($sql);} function editfocusphoto_menu(){ global $wpdb; include focusphoto-admin.php;} function focusphoto_admin_actions(){ add_options_page(焦点图管理, 焦点图管理, 1,Focus-photo, editfocusphoto_menu);} add_action(admin_menu, focusphoto_admin_actions);? focusphoto-admin.php 包含以下4个函数focusphoto_list() 焦点图列表focusphoto_delete($photoid) 删除指定$photoid的记录focusphoto_edit($photoid) 编辑指定$photoid的记录focusphoto_add() 添加焦点图 ?php /* * Created on Jan 31, 2012 * Author: Henry Poter */ function focusphoto_list() { global $wpdb; $addlink site_url()./wp-admin/options-general.php?pageFocus-photoactaddfocusphoto; $photos $wpdb-get_results(SELECT * FROM . $wpdb-prefix . focusphoto order by id desc limit 10); //print_r($photos); if (count($photos) 0) {?div idicon-edit classicon32 icon32-posts-postbr/divh2焦点图 a href?php echo $addlink; ? classadd-new-h2添加焦点图/a /h2?php echo p stylecolor:red;暂时没有焦点图请a href$addlink点击添加/p; } else {?div idicon-edit classicon32 icon32-posts-postbr/divh2焦点图 a href?php echo $addlink; ? classadd-new-h2添加焦点图/a /h2 table classwp-list-table widefat fixed posts cellspacing0 thead tr th scopecol classmanage-column column-cb check-column style input typecheckbox /th th scopecol classmanage-column column-title style span标题/spanspan classsorting-indicator/span /th th scopecol class manage-column column-title style span图片地址/spanspan classsorting-indicator/span /th th scopecol classmanage-column column-title style链接到/th /tr /thead tbody idthe-list?php foreach ($photos as $photo) {? tr idpost-1 classpost-1 post type-post status-publish format-standard hentry category-uncategorized iedit author-self valigntop th scoperow classcheck-columninput typecheckbox namepost[] value?php echo $photo-id;?/th td classpost-title page-title column-title stronga classrow-title href?pageFocus-photoacteditfocusphotophotoid?php echo $photo-id;? title?php echo $photo-title;??php echo $photo-title;?/a/strong div classrow-actionsspan classedit a href?pageFocus-photoacteditfocusphotophotoid?php echo $photo-id;?编辑/a | /span span classinline hide-if-no-jsa href?pageFocus-photoactdeletefocusphotophotoid?php echo $photo-id;?删除/a | /span span classviewa href?php echo $photo-photourl;? relpermalink查看焦点图/a/span span classviewa href?php echo $photo-linkto;? relpermalink查看相关链接/a/span /div /td td classpost-title page-title column-title?php echo $photo-photourl;?/td td classauthor column-author?php echo $photo-linkto;?/td /tr?php }//end foreach }//end if? /tbody/table?php if (isset ($_GET[photoid]) $_GET[act] editfocusphoto) { $photoid $_GET[photoid]; focusphoto_edit($photoid); } if (isset ($_GET[photoid]) $_GET[act] deletefocusphoto) { $photoid $_GET[photoid]; focusphoto_delete($photoid); } if (isset ($_GET[act]) $_GET[act] addfocusphoto) { focusphoto_add(); } } //end focusphoto_list() function focusphoto_delete($photoid) { global $wpdb; if (!is_numeric($photoid)) { die(p stylecolor:red;参数photoid错误/p); } $table $wpdb-prefix . focusphoto; $result $wpdb-query(DELETE FROM $table WHERE id $photoid ); if ($result 1) { echo script languejavascript alert(删除成功);/script; header(location: . $_SERVER[REQUEST_URI]); }} function focusphoto_edit($photoid) { global $wpdb; if (!is_numeric($photoid)) { die(p stylecolor:red;参数photoid错误/p); } if (isset ($_POST[editphoto])) { $newphoto array ( photourl $_POST[photourl], linkto $_POST[linkto], title $_POST[title] ); print_r($newphoto); $result $wpdb-update($wpdb-prefix . focusphoto, $newphoto, array ( id $photoid ), $format null, $where_format null); //if($result 1){ echo script languejavascript alert(编辑成功);/script; header(location: . site_url()./wp-admin/options-general.php?pageFocus-photo); //} } $photo $wpdb-get_results(SELECT * FROM . $wpdb-prefix . focusphoto . WHERE id$photoid); // print_r($photo);?br/form action methodpost table classwidefat cellspacing0 thead tr th scopecol classmanage-column column-title colspan4编辑焦点图 /th /tr /thead tbody trtd/tdtd/td/tr trtd图片地址/tdtdinput size80 tabindex1 autocompleteoff typetext value?php echo $photo[0]-photourl ;? namephotourl /td/tr trtd链接到/tdtdinput size80 tabindex2 typetext value?php echo $photo[0]-linkto ;? namelinkto /td/tr trtd标题/tdtdinput size80 tabindex3 typetext value?php echo $photo[0]-title ;? nametitle /td/tr trtd/tdtdinput tabindex4 typesubmit nameeditphoto value保存 stylewidth:80px;/td/tr /tbody /table /form ?php } //end focusphoto_edit() function focusphoto_add() { global $wpdb; if (isset ($_POST[addphoto])) { $photo array ( photourl $_POST[photourl], linkto $_POST[linkto], title $_POST[title] ); $wpdb-insert($wpdb-prefix . focusphoto, $photo); header(location: . $_SERVER[REQUEST_URI]); }?br/ form action methodpost table classwidefat cellspacing0 thead tr th scopecol classmanage-column column-title colspan4添加焦点图 /th /tr /thead tbody trtd/tdtd/td/tr trtd图片地址/tdtdinput size80 tabindex1 typetext value namephotourl /td/tr trtd链接到/tdtdinput size80 tabindex2 typetext value namelinkto /td/tr trtd标题/tdtdinput size80 tabindex3 typetext value nametitle /td/tr trtd/tdtdinput tabindex4 typesubmit nameaddphoto value添加 stylewidth:80px;/td/tr /tbody /table /form?php } //end focusphoto_add() focusphoto_list();? 转载于:https://www.cnblogs.com/qqyuhaitao/p/3291820.html