0

How to do a pagination in search result? I have already an excerpt script. All I need is a script for pagination. Pls help me. Thanks

   function wpse_allowedtags() {
    return '<script>,<style>,<br>,<em>,<i>,<ul>'; 
   }
   if ( ! function_exists( 'wpse_custom_wp_trim_excerpt' ) ) : 

function wpse_custom_wp_trim_excerpt($wpse_excerpt) {
$raw_excerpt = $wpse_excerpt;
    if ( '' == $wpse_excerpt ) {

        $wpse_excerpt = get_the_content('');
        $wpse_excerpt = strip_shortcodes( $wpse_excerpt );
        $wpse_excerpt = apply_filters('the_content', $wpse_excerpt);
        $wpse_excerpt = str_replace(']]>', ']]&gt;', $wpse_excerpt);
        $wpse_excerpt = strip_tags($wpse_excerpt, wpse_allowedtags());

            $excerpt_word_count = 200;
            $excerpt_length = apply_filters('excerpt_length', $excerpt_word_count); 
            $tokens = array();
            $excerptOutput = '';
            $count = 0;

            preg_match_all('/(<[^>]+>|[^<>\s]+)\s*/u', $wpse_excerpt, $tokens);

            foreach ($tokens[0] as $token) { 

                if ($count >= $excerpt_length && preg_match('/[\,\;\?\.\!]\s*$/uS', $token)) { 
                    $excerptOutput .= trim($token);
                    break;
                }

                $count++;
                $excerptOutput .= $token;
            }

        $wpse_excerpt = trim(force_balance_tags($excerptOutput));

            $excerpt_end = ' <a href="'. esc_url( get_permalink() ) . '">' . '&nbsp;&raquo;&nbsp;' . sprintf(__( 'Read more about: %s &nbsp;&raquo;', 'wpse' ), get_the_title()) . '</a>'; 
            $excerpt_more = apply_filters('excerpt_more', ' ' . $excerpt_end); 

            //$pos = strrpos($wpse_excerpt, '</');
            //if ($pos !== false)
            // Inside last HTML tag
            //$wpse_excerpt = substr_replace($wpse_excerpt, $excerpt_end, $pos, 0); /* Add read more next to last word */
            //else
            // After the content
            $wpse_excerpt .= $excerpt_more; /*Add read more in new paragraph */

        return $wpse_excerpt;   

    }
    return apply_filters('wpse_custom_wp_trim_excerpt', $wpse_excerpt, $raw_excerpt);
}

endif; 

remove_filter('get_the_excerpt', 'wp_trim_excerpt');
add_filter('get_the_excerpt', 'wpse_custom_wp_trim_excerpt');
  • You cannot paginate the function above. That function just alters the the_excerpt(). You need to paginate your query. Please use the site search for pagination solutions. :-) – Pieter Goosen Mar 23 '15 at 6:34
  • what site? @PieterGoosen – user3098728 Mar 23 '15 at 6:36
  • This one :-). Look top right corner, there is a search box. – Pieter Goosen Mar 23 '15 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.