Having trouble with some shortcode
-
Hello there, having some issues with a carousel shortcode.
The carousel is pulling 3 posts and rotate them however while the images and the post titles are changing, the post category and the post URL are not. Sample of the carousel is visible on the right column in the page linked.
Any suggestion?//Carousel shortcode for sidebar. function dl_carousel_shortcode( $atts ) { //Find three posts of the same post type and same category global $post; $category = get_the_category($post->ID); print_r($category); $args = array( 'posts_per_page' => 3, 'post_type' => $post->post_type, 'post__not_in' => array($post->ID), 'category' => $category[0]->term_id ); $carouselposts = get_posts($args); $output = '<div class="ob-carousel no-controls"><div class="result">'; $count = 1; foreach($carouselposts as $cpost){ $url = get_permalink( $cpost->ID ); $image = wp_get_attachment_image_src( get_post_thumbnail_id( $cpost->ID ), 'result-large' ); $img_url = $image[0]; if($count === 1){ $show = 'active'; } else { $show = ''; } print_r($url); $category1 = dl_post_meta( $cpost->ID ); print_r($category1); $output .= '<div class="result_wrap ' . $show . ' ob-wrap-' . $count . '">'; $output .= '<header class="post"><p class="post-meta">' . $category . '</p><h2 class="entry-title"><a href="' . $url . '"> ' . $cpost->post_title . ' </a></h2></header>'; $output .= '<a href="' . $url . '"><img src="' . $img_url . '" width="320" height="270" /></a></div>'; $count++; } $output .= '</div></div>'; return $output; } add_shortcode( 'dl_carousel', 'dl_carousel_shortcode' );The page I need help with: [log in to see the link]
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
The topic ‘Having trouble with some shortcode’ is closed to new replies.