自定义帖子类型元框不显示
继续本教程:http://wp. tutsplus.com/tutorials/create-a-responsive-slider-plugin-with-flexslider/
我正在尝试添加一些元框以允许添加更多内容到每张幻灯片。从“链接”元框开始,这是我的 slider-img-type.php 代码:
<?php
define('CPT_NAME', "Slider Images");
define('CPT_SINGLE', "Slider Image");
define('CPT_TYPE', "slider-image");
define('CPT_THUMB_SIZE', 500);
add_theme_support('post-thumbnails', array('slider-image'));
function efs_register() {
$args = array(
'label' => __(CPT_NAME),
'singular_label' => __(CPT_SINGLE),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'supports' => array('title', 'editor', 'thumbnail')
);
register_post_type(CPT_TYPE , $args );
set_post_thumbnail_size(CPT_THUMB_SIZE);
}
add_action('init', 'efs_register');
add_action("admin_init", "efs_meta_box");
function efs_meta_box(){
add_meta_box("projInfo-meta", "EFS Options", "efs_meta_options", "efs", "side", "low");
}
function efs_meta_options(){
global $post;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
$custom = get_post_custom($post->ID);
$link = $custom["projLink"][0];
?>
<label>Link:</label><input name="projLink" value="<?php echo $link; ?>" />
<?php
}
add_action('save_post', 'save_efs_link');
function save_efs_link(){
global $post;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){
return $post_id;
}else{
update_post_meta($post->ID, "projLink", $_POST["projLink"]);
}
}
?>
也许我遗漏了一些明显的东西,但当我尝试添加新的滑块图像帖子类型时,我无法显示链接输入字段。
任何帮助将不胜感激。
谢谢, James
基于 rmlumley 的代码修改了代码:
function efs_meta_options(){
global $post;
$custom = get_post_custom($post->ID);
$link = $custom["projLink"][0];
?>
<label>Link:</label><input name="projLink" value="<?php echo $link; ?>" />
<?php
}
add_action('save_post', 'save_efs_link');
function save_efes_link($post_ID = 0){
$post_ID = (int) $post_ID;
$post_type = get_post_type( $post_ID );
$post_status = get_post_status( $post_ID );
if ($post_type) {
update_post_meta($post->ID, "projLink", $_POST["projLink"]);
}
return $post_ID;
} ?>
我刚刚注意到教程评论中发布了另一个解决方案,但这似乎对我不起作用:
http://wp.tutsplus.com/tutorials/create-a-responsive-slider-plugin-with-flexslider/#comment-14080
我认为评论删除了正确的代码显示锚点标签:
$slider.='<li><a href='.$slide_link.'>'.$img.'</a></li>';
我尝试在“值”输入字段中添加一个带有 url 的自定义字段“link_slide_to”,但幻灯片在锚点悬停时仍然不显示 url。
Following on from this tutorial: http://wp.tutsplus.com/tutorials/create-a-responsive-slider-plugin-with-flexslider/
I am trying to add some meta-boxes to allow the addition of further content to each slide. Starting with a 'link' metabox here is my code for slider-img-type.php:
<?php
define('CPT_NAME', "Slider Images");
define('CPT_SINGLE', "Slider Image");
define('CPT_TYPE', "slider-image");
define('CPT_THUMB_SIZE', 500);
add_theme_support('post-thumbnails', array('slider-image'));
function efs_register() {
$args = array(
'label' => __(CPT_NAME),
'singular_label' => __(CPT_SINGLE),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => true,
'supports' => array('title', 'editor', 'thumbnail')
);
register_post_type(CPT_TYPE , $args );
set_post_thumbnail_size(CPT_THUMB_SIZE);
}
add_action('init', 'efs_register');
add_action("admin_init", "efs_meta_box");
function efs_meta_box(){
add_meta_box("projInfo-meta", "EFS Options", "efs_meta_options", "efs", "side", "low");
}
function efs_meta_options(){
global $post;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
$custom = get_post_custom($post->ID);
$link = $custom["projLink"][0];
?>
<label>Link:</label><input name="projLink" value="<?php echo $link; ?>" />
<?php
}
add_action('save_post', 'save_efs_link');
function save_efs_link(){
global $post;
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ){
return $post_id;
}else{
update_post_meta($post->ID, "projLink", $_POST["projLink"]);
}
}
?>
Maybe I'm missing something obvious but I can't get the Link input field to appear when I try to add a new Slider Image post type.
Any help would be most appreciated.
Thanks,
James
Amended Code based on rmlumley's code:
function efs_meta_options(){
global $post;
$custom = get_post_custom($post->ID);
$link = $custom["projLink"][0];
?>
<label>Link:</label><input name="projLink" value="<?php echo $link; ?>" />
<?php
}
add_action('save_post', 'save_efs_link');
function save_efes_link($post_ID = 0){
$post_ID = (int) $post_ID;
$post_type = get_post_type( $post_ID );
$post_status = get_post_status( $post_ID );
if ($post_type) {
update_post_meta($post->ID, "projLink", $_POST["projLink"]);
}
return $post_ID;
} ?>
I've just noticed another solution posted to the comments of the tutorial but again this doesn't seem to be working for me:
http://wp.tutsplus.com/tutorials/create-a-responsive-slider-plugin-with-flexslider/#comment-14080
I think the comments stripped out the correct code for displaying the anchor tag:
$slider.='<li><a href='.$slide_link.'>'.$img.'</a></li>';
I tried adding a custom field 'link_slide_to' with a url in the 'value' input field but the slide still displays no url on anchor hover.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
几个月前,我帮助了遇到类似问题的人,
I helped someone with a similar problem a few months ago, hopefully this will help you out. Let me know if you have any questions.