1

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.

1 Answer 1

0

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.

7
  • Thanks rmlumley, I've edited the code based on your code but still no luck in getting the link box to display:
    – James R
    Jan 9, 2012 at 14:05
  • I don't know why this would matter, but just to eliminate it as a possibility, have you tried writing it out without the label? Just the Input and maybe some text under it.
    – rmlumley
    Jan 9, 2012 at 15:04
  • That didn't make a difference I'm afraid. Would it be anything to do with: 'supports' => array('title', 'editor', 'thumbnail', 'custom-fields')
    – James R
    Jan 9, 2012 at 17:01
  • See above for another solution which doesn't seem to be working for me either.
    – James R
    Jan 9, 2012 at 17:25
  • You know, I think I found it. Change the "efs", "side", "low") part of your add_meta_box to "CPT_TYPE", "side", "low")
    – rmlumley
    Jan 9, 2012 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.