WordPress实现的首页幻灯片展示功能示例
'post', // Admin page (or post type)
add_action( 'load-post.php', 'sola_post_meta_boxes_setup' );
echo '<input type="hidden" value="', wp_create_nonce(basename(__FILE__)), '" />';
接下来修改slider.php,使用post meta box实现,就需要根据post的meta信息搜索幻灯片,代码如下
break;}
);
}
update_post_meta($post_id, $field['id'], $new);
'meta_key' => 'sola-post-slider',
}
'sola_seo_box_format', // Callback function
用get_posts()和meta_query参数结合,就可以达到目的,有了数据,直接循环输出就行
foreach ($fields as $field) {希望本文所述对大家基于wordpress的程序设计有所帮助。
'type' => 'checkbox',echo '<table>';
}
echo '<input type="radio" value="' . $option['value'] . '"' . ( $meta == $option['value'] ? ' checked="checked"' : '' ) . ' />' . $option['name'];
// get current post meta data
case 'checkbox':
后面的代码会自动根据数组填充的内容创建Post Meta Box */
echo '</select>';
}
case 'radio':
switch ($field['type']) {
break;
function sola_post_meta_boxes_setup() {
case 'text':
array(
// Use nonce for verification
function sola_save_post_meta_boxes($post_id) {
2.读取幻灯片文章
break;$post_type = get_post_type_object( $post->post_type );
'sola-post-slider-class', // Unique ID
)
//Get the post type object.
foreach ($field['options'] as $option) {
$new = $_POST[$field['id']];
//Check autosave
delete_post_meta($post_id, $field['id'], $old);
/* Create one or more meta boxes to be displayed on the post editor screen. */
1.创建Post Meta Box
function sola_seo_box_format(){
return $post_id;
$old = get_post_meta($post_id, $field['id'], true);
add_action( 'load-post-new.php', 'sola_post_meta_boxes_setup' );
echo '<select>';
if (!wp_verify_nonce($_POST['sola_meta_box_nonce'], basename(__FILE__))) {
'. $field['desc'];
if ( !current_user_can( $post_type->cap->edit_post, $post_id ) )
echo '<input type="checkbox"' . ( $meta ? ' checked="checked"' : '' ) . ' />';
echo '<input type="text" value="'. ($meta ? $meta : $field['default']) . '" size="30" />'. '
'posts_per_page' => 4,
这段代码会在文章创建和编辑页面创建如下所示的Post Meta Box :

echo '</table>';
break;
echo '<td>'.'</tr>';
'id' => 'sola-post-slider',
}
} elseif ('' == $new && $old) {
'<th><label for="'. $field['id'] .'">'. $field['name']. '</strong></label></th>'.
echo '<option '. ( $meta == $option ? ' selected="selected"' : '' ) . '>'. $option . '</option>';
case 'textarea':
$fields = array(
add_action( 'add_meta_boxes', 'sola_add_post_meta_boxes' );
'desc' => 'Check this box and make the post a slider',
function sola_add_post_meta_boxes() {
global $fields, $post;
'meta_value' => 'on',
break;
主要是使用了WordPress的自定义文章字段的功能来判断是否需要显示在首页:
global $fields,$post;if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
'default' => ''
/* Meta box setup function. */
/* Fire our meta box setup function on the post editor screen. */
add_action( 'save_post', 'sola_save_post_meta_boxes', 10, 2 );
/* 这是需要修改的两处之一,本功能只需要一个checkbox,将checkbox的title、id等属性填充到$fields数组中,
写文章时,勾选在首页显示幻灯片,这篇文章就会自动推送到首页幻灯片中。
//Verify nonce}
'default' // Priority
'name' => __('是否在首页幻灯显示'),
__('首页幻灯片'), // Title
}
对于WordPress拓展性这么优秀的程序来说,是没有什么不能实现的。很多在建站的时候,都会选择在首页使用幻灯片,可以展示比较醒目的内容。今天就来一个首页幻灯片的制作教程,相信幻灯片在各种企业包括个人网站上面用处还是很大的,做完之后效果和本站首页的一样。
'<td>';'. $field['desc'];
}
if ($new && $new != $old) {
echo '<textarea cols="60" rows="4">'. ($meta ? $meta : $field['default']) . ''. '
case 'select':
foreach ($field['options'] as $option) {
}
echo '<tr>'.
query_posts($args);
}
foreach ($fields as $field) {
$meta = get_post_meta($post->ID, $field['id'], true);
}
return $post_id;
'side', // Context
);
/* Add meta boxes on the 'add_meta_boxes' hook. */
$args = array(
);
相关热词: 功能
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jz/wp/5184.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
ludou_se_only); } add_action(s
时间:2021-01-23
-
所以经常导致输错密码的
时间:2021-01-23
-
WordPress措施打开速度慢的
时间:2021-01-22
-
WordPress回覆评论自动添加
时间:2021-01-22
-
我们可以通过下面的代码
时间:2021-01-22
-
如何修改WordPress默认脚色
时间:2021-01-20
-
同样的修改文件就行
时间:2021-01-20
-
少数善意的转载者既使没
时间:2021-01-20
热门文章
-
WordPress新手安装教程(图文)
时间:2020-12-28
-
在设置菜单中增加WordPress私密 隐藏的全部
时间:2021-01-10
-
WordPress博客程序常见错误的解决方法
时间:2020-12-28
-
WordPress程序打开速度慢的三种解决方法
时间:2021-01-10
-
wordpress使用代码在每篇文章尾部添加版权
时间:2020-12-14
-
WordPress博客措施常见错误的办理要领
时间:2021-01-15
-
关于WordPress的SEO优化相关的一些PHP页面脚
时间:2021-01-07
-
WordPress措施打开速度慢的三种办理要领
时间:2021-01-22
-
详解WordPress中的头像缓存和署理中的缓存
时间:2021-01-15
-
少数善意的转载者既使没有看到版权信息
时间:2021-01-20
