您现在的位置是:首页 > cms教程 > WordPress教程WordPress教程

wordpress增删改查

许欣英2025-03-19WordPress教程已有人查阅

导读该插件在wordpress-3.3.1-zh_CN版本下开发,主要用于在后台管理首页焦点图(图片轮播)。存放焦点图信息的表 focusphoto(id,photourl,linkto,title,description)该插件包括2个

该插件在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.net
Description: 该插件在wordpress-3.3.1-zh_CN版本下开发,主要用于在后台管理首页焦点图(图片轮播)
Author: Henry Poter
Version: 1.0
Author 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)
) CHARSET=UTF8";
$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?page=Focus-photo&act=addfocusphoto";
$photos = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "focusphoto order by id desc limit 10");
//print_r($photos);
if (count($photos) <= 0) {
?>
<div id="icon-edit" class="icon32 icon32-posts-post"><br></div>
<h2>焦点图 <a href="<?php echo $addlink; ?>" class="add-new-h2">添加焦点图</a> </h2>
<?php
echo "<p style='color:red;'>暂时没有焦点图,请<a href='$addlink'>点击添加</p>";
} else {
?>
<div id="icon-edit" class="icon32 icon32-posts-post"><br></div>
<h2>焦点图 <a href="<?php echo $addlink; ?>" class="add-new-h2">添加焦点图</a> </h2>
<table class="wp-list-table widefat fixed posts" cellspacing="0">
<thead>
<tr>
<th scope="col" class="manage-column column-cb check-column" style="">
<input type="checkbox">
</th>
<th scope="col" class="manage-column column-title" style="">
<span>标题</span><span class="sorting-indicator"></span>
</th>
<th scope="col" class=" manage-column column-title" style="">
<span>图片地址</span><span class="sorting-indicator"></span>
</th>
<th scope="col" class="manage-column column-title" style="">链接到</th>
</tr>
</thead>
<tbody id="the-list">
<?php foreach ($photos as $photo) {?>
<tr id="post-1" class="post-1 post type-post status-publish format-standard hentry category-uncategorized iedit author-self" valign="top">
<th scope="row" class="check-column"><input type="checkbox" name="post[]" value="<?php echo $photo->id;?>"></th>
<td class="post-title page-title column-title">
<strong><a class="row-title" href="?page=Focus-photo&act=editfocusphoto&photoid=<?php echo $photo->id;?>" title="<?php echo $photo->title;?>"><?php echo $photo->title;?></a></strong>
<div class="row-actions"><span class="edit">
<a href='?page=Focus-photo&act=editfocusphoto&photoid=<?php echo $photo->id;?>'>编辑</a> | </span>
<span class="inline hide-if-no-js"><a href='?page=Focus-photo&act=deletefocusphoto&photoid=<?php echo $photo->id;?>'>删除</a> | </span>
<span class="view"><a href="<?php echo $photo->photourl;?>" rel="permalink">查看焦点图</a></span>
<span class="view"><a href="<?php echo $photo->linkto;?>" rel="permalink">查看相关链接</a></span>
</div>
</td>
<td class="post-title page-title column-title"><?php echo $photo->photourl;?></td>
<td class="author 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 style='color:red;'>参数photoid错误!</p>");
}
$table = $wpdb->prefix . 'focusphoto';
$result = $wpdb->query("DELETE FROM $table WHERE id = $photoid ");
if ($result == 1) {
echo "<script langue='javascript'> alert('删除成功!');</script>";
header("location: " . $_SERVER['REQUEST_URI']);
}
}
function focusphoto_edit($photoid) {
global $wpdb;
if (!is_numeric($photoid)) {
die("<p style='color: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 langue='javascript'> alert('编辑成功!');</script>";
header("location: " . site_url().'/wp-admin/options-general.php?page=Focus-photo');
//}
}
$photo = $wpdb->get_results("SELECT * FROM " .
$wpdb->prefix . "focusphoto" . " WHERE id=$photoid");
// print_r($photo);
?>
<br/>
<form action="" method="post">
<table class="widefat" cellspacing="0" >
<thead>
<tr>
<th scope="col" class="manage-column column-title" colspan="4">编辑焦点图
</th>
</tr>
</thead>
<tbody>
<tr><td></td><td></td></tr>
<tr><td>图片地址</td><td><input size="80" tabindex="1" autocomplete="off" type='text' value='<?php echo $photo[0]->photourl ;?>' name='photourl' > </td></tr>
<tr><td>链接到</td><td><input size="80" tabindex="2" type='text' value='<?php echo $photo[0]->linkto ;?>' name='linkto' ></td></tr>
<tr><td>标题</td><td><input size="80" tabindex="3" type='text' value='<?php echo $photo[0]->title ;?>' name='title' ></td></tr>
<tr><td></td><td><input tabindex="4" type='submit' name='editphoto' value='保存' style='width: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="" method="post">
<table class="widefat" cellspacing="0">
<thead>
<tr>
<th scope="col" class="manage-column column-title" colspan="4">添加焦点图
</th>
</tr>
</thead>
<tbody>
<tr><td></td><td></td></tr>
<tr><td>图片地址</td><td><input size="80" tabindex="1" type='text' value='' name='photourl' > </td></tr>
<tr><td>链接到</td><td><input size="80" tabindex="2" type='text' value='' name='linkto' ></td></tr>
<tr><td>标题</td><td><input size="80" tabindex="3" type='text' value='' name='title' ></td></tr>
<tr><td></td><td><input tabindex="4" type='submit' name='addphoto' value='添加' style='width:80px;'></td></tr>
</tbody>
</table>
</form>
<?php
} //end focusphoto_add()
focusphoto_list();
?>

本文标签:

很赞哦! ()

相关源码

  • (自适应)证书授权书防伪查询系统pbootcms模板本模板基于PbootCMS系统开发,为各类证书查询机构设计,可快速构建高效安全的证书核验平台。采用响应式布局技术,自动适配手机端操作,支持批量导入证书数据,提供便捷的查询接口,满足机构证书管理及用户在线核验需求。查看源码
  • (PC+WAP)蓝色低碳环保隔断板装修装饰类网站pbootcms源码下载本款基于PbootCMS开发的网站模板为活动隔断板、装修装饰行业打造,特别适合移动隔断、环保隔断、办公分区等产品的展示与推广。查看源码
  • (自适应响应式)HTML5简繁双语电子元器件设备制造Pbootcms模板下载本模板为电子科技设备制造、电子元件生产等高科技企业设计,采用PbootCMS内核开发,具备简繁双语切换功能。模板设计充分考虑了电子科技行业的技术展示需求,能够专业呈现各类电子元器件、电路板、智能设备的参数规格和应用方案。查看源码
  • (PC+WAP)绿色市政园林建筑设计绿化营销型pbootcms网站模板本模板基于PbootCMS系统开发,为园林绿化、景观设计类企业设计,特别适合市政园林、景观工程、绿化养护等企业使用。采用双端适配技术查看源码
  • (自适应响应式)pbootcms紫色美容整形机构企业模板下载基于PbootCMS内核开发的响应式网站模板,为医疗美容机构、整形医院等企业设计,提供完整的线上展示平台采用紫色系配色方案,整体风格专业大气。模板包含首页轮播、服务项目、专家团队、案例展示等核心模块,能够充分展示医疗美容机构的专业服务和特色优势。查看源码
  • (响应式)企业管理人力资源服务类pbootcms模板源码下载为人力资源服务及企业管理设计的响应式网站模板,基于PbootCMS内核开发。通过宽屏布局优化岗位展示效果,简洁界面聚焦人才服务核心业务,自适应技术确保在PC端与手机端查看源码
分享笔记 (共有 篇笔记)
验证码: