shortcode posted always at top of page/post
-
Hi,
I experienced the following issue: posting a new article with PP short code, the output was always put on top of the pages. I solved the issue editing the shortcode code as following:NOTE: bolded text is the added code
function showlist( $atts ){ extract( shortcode_atts( array( 'catid' => '', 'lenght' => '10', 'listclass' => 'aptools-list', 'header' => '2', 'headerclass' => 'aptools-list-header', 'excerpt' => 'false', 'image' => 'false', 'wrapper' => 'false', 'wrapperclass' => 'aptools-list-wrapper' ), $atts ) ); $hopen = '<h'.$header.' class='.$headerclass.'>'; $hclose = '</h'.$header.'>'; if( $catid !== '' ): $args = array( 'category__in' => array($catid), 'posts_per_page' => $lenght ); endif; $page = new WP_Query( $args ); <strong>ob_start();</strong> if( $page->have_posts() ): if( $wrapper !== 'false'){ echo '<div class="'.$wrapperclass.'">'; } echo '<ul class="'.$listclass.'">'; while( $page->have_posts() ): $page->the_post(); echo '<li>'; echo '<a href="'.get_permalink().'">'.get_the_title().'</a>'; if( $image !== 'false' && has_post_thumbnail() ){ the_post_thumbnail( $image ); } if( $excerpt === 'true' ) echo ' <span>'.get_the_excerpt().'</span>'; echo '</li>'; endwhile; echo '</ul>'; if( $wrapper !== 'false'){ echo '</div>'; } endif; <strong>$content = ob_get_clean();</strong> wp_reset_postdata(); <strong>return $content;</strong> }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘shortcode posted always at top of page/post’ is closed to new replies.