WP Admin Slider Control
-
Since this is in the admin, it’s not going to be easy to share, but we have a slider control on our home page. In the admin area, we can add as many items as we want to the slider and include things like the logo, a description and a link. It’s the link part that is broken. Instead of presenting a text field to input the proper link, it instead just displays the link and doesn’t allow you to edit it.
These are in metaboxes that are included in the metaboxes.php file. This is the code for that section:
$home_metaboxes = array( /***=================================================================== slideshow ======================================================================= ***/ 'slideshow' => array( 'title' => 'Homepage slideshow', 'fields' => array( 'slides' => array( 'title' => 'Slides', 'type' => 'group', 'subfields' => array( 'image' => array( 'title' => 'Slide Background', 'type' => 'media', 'image_size' => 'large', 'get' => 'image' ), 'image_align' => array( 'title' => 'Image Alignment', 'type' => 'select', 'default' => 'middle', 'options' => array( 'top' => 'Top', 'middle' => 'Middle', 'bottom' => 'Bottom' ) ), 'text' => array( 'title' => 'Slide Text', 'type' => 'textarea' ), 'link_text' => array( 'title' => 'Link Text' ), 'link' => array( 'title' => 'Link to:', 'type' => 'post', // 'type' => 'textarea', 'get' => 'url' ) ) ) ) ),
The ‘link’ section is the problem. I’ve commented out the code I added to fix the issue: // ‘type’ => ‘textarea’ The default code is ‘get’ => ‘url’.
If I set this to ‘type’ => ‘textarea’, it fixes the issue on the admin page, but causes an error to appear on the homepage pointing to this line of code in a separate file called post.php in a folder called Cloud_Options:
public static function get_option( $post_id, $spec ){ if ( is_string( $spec ) ){ $prop_to_get = $spec ; } else { $prop_to_get = self::property_to_get( $spec['get'] ); } $value = '' ; switch ( $prop_to_get ){ case 'ID' : return $post_id ; break; case 'post' : $value = get_post( $post_id ) ; break; case 'post_title' : $post = get_post( $post_id ) ; return $post->post_title ; break; case 'post_content' : $post = get_post( $post_id ) ; return apply_filters( 'the_content', $post->post_content ) ; break; case 'post_excerpt' : $post = get_post( $post_id ) ; return apply_filters( 'the_excerpt', $post->post_excerpt ) ; break; case 'post_thumbnail' : $image_size = isset( $spec['image_size'] ) ? $spec['image_size'] : 'full' ; return get_the_post_thumbnail( $post_id, 'thumbnail' ) ; break; case 'post_thumbnail_id' : $attachment_id = get_post_thumbnail_id( $post_id ) ; return $attachment_id ; break; case 'post_thumbnail_url' : $attachment_id = get_post_thumbnail_id( $post_id ) ; $image_size = isset( $spec['image_size'] ) ? $spec['image_size'] : 'full' ; $image_info = wp_get_attachment_image_src( $attachment_id, $image_size ) ; return $image_info[0] ; break; case 'url' : return get_permalink( $post_id ); break ; } }
It’s in the first else statement.
$prop_to_get = self::property_to_get( $spec['get'] );
Which I think is strange. I’m not sure how the two items are related.Any insight would be appreciated.
- The topic ‘WP Admin Slider Control’ is closed to new replies.