Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Getting the first quote or blockquote element to display in excerpt

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #168970
    Jason Penezich
    Participant

    I’m doing a custom excerpt as a function but need a way for quote format posts to grab and display the first quote or blockquote used in the content.

    Currently this is what I am doing:

    function improved_trim_excerpt($text) {
            global $post;
            if ( '' == $text ) {
                    $text = get_the_content('');
                    $text = apply_filters('the_content', $text);
                    $text = str_replace('\]\]\>', ']]>', $text);
                    $text = preg_replace('@<script[^>]*?>.*?</script>@si', '', $text);
                    if ( has_post_format('quote') ) {
                        $text = strip_tags($text, '<quote> <blockquote> <p>');
                    }
                    elseif ( has_post_format( 'video' ) ) {
                        $postcustom = get_post_custom_keys();
                        $text = strip_tags($text, '<p>');
                        if ($postcustom){
                          $i = 1;
                          foreach ($postcustom as $key){
                            if (strpos($key,'oembed')){
                              foreach (get_post_custom_values($key) as $video){
                                if ($i == 1){
                                  $text = $video.$text;
                                }
                              $i++;
                              }
                            }  
                          }
                        }
                    }
                    else {
                        $text = strip_tags($text, '<p> <a> <ul> <ol> <li>');
                    }
                    $excerpt_length = 35;
                    $words = explode(' ', $text, $excerpt_length + 1);
                    if (count($words)> $excerpt_length) {
                        array_pop($words);
                        array_push($words, '<a>ID) . '"> ....</a>' );
                        $text = implode(' ', $words);
                    }
    
            }       
            return $text;
    }
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('the_excerpt', 'improved_trim_excerpt'); 
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.