• Trying to pull content into the flex slider from wordpress

    <?php the_excerpt(); ?> will not working even if I define a text limit value

    Php

    <?php $id=247;
    $post = get_post($id);
    $content = apply_filters('the_content', $post->post_content);  ?>
    
    			<div class="da-slide">
    				<h2><?php the_title(); ?></h2>
    				<p><?php the_excerpt(10); ?></p>
    				<a href="<?php the_permalink(); ?>" class="da-link">Read more</a>
    				<div class="da-img"><img src="<?php echo catch_that_image() ?>"></div>
    			</div>
    
    endforeach;
    ?>

    Custom functions added works fine everywhere else

    function  strip_shortcode_gallery( $content ) {
        preg_match_all( '/'. get_shortcode_regex() .'/s', $content, $matches, PREG_SET_ORDER );
        if ( ! empty( $matches ) ) {
            foreach ( $matches as $shortcode ) {
                if ( 'gallery' === $shortcode[2] ) {
                    $pos = strpos( $content, $shortcode[0] );
                    if ($pos !== false)
                        return substr_replace( $content, '', $pos, strlen($shortcode[0]) );
                }
            }
        }
        return $content;
    }
    
    function catch_that_image() {
      global $post, $posts;
      $first_img = '';
      ob_start();
      ob_end_clean();
      $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_img = $matches[1][0];
    
      if(empty($first_img)) {
        $first_img = "/path/to/default.png";
      }
      return $first_img;
    }
    
    function content($limit) {
     $content = explode(' ', get_the_content(), $limit);
     if (count($content)>=$limit) {
     array_pop($content);
     $content = implode(" ",$content).'...';
     } else {
     $content = implode(" ",$content);
     }
     $content = preg_replace('/\[.+\]/','', $content);
     $content = apply_filters('the_content', $content);
     $content = str_replace(']]>', ']]>', $content);
     return $content;
    }
    
    function excerpt($limit) {
     $excerpt = explode(' ', get_the_excerpt(), $limit);
     if (count($excerpt)>=$limit) {
     array_pop($excerpt);
     $excerpt = implode(" ",$excerpt).'...';
     } else {
     $excerpt = implode(" ",$excerpt);
     }
     $excerpt = preg_replace('<code>\[[^\]]*\]</code>','',$excerpt);
     return $excerpt;
    }

    Works fine in my news section

    <!-- start: Latest News -->
    
    		      		<div class="row">
    
    					<?php
    $posts = get_posts('numberposts=3&order=ASC&orderby=post_title');
    foreach ($posts as $post) : setup_postdata( $post ); ?>	<div class="span3">
    <div class="picture">
    
    								<a href="<?php echo catch_that_image() ?>" rel="image" title="<?php the_title(); ?>">
    									<img src="<?php echo catch_that_image() ?>">
    									<div class="image-overlay-zoom"></div>
    								</a>
    
    							</div>
    							<div class="item-description">
    								<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
    								<p><?php echo excerpt('25'); ?></p>
    							</div>
            				</div>
    
                        <?php
    endforeach;
    ?>
Viewing 1 replies (of 1 total)
  • Thread Starter badincite

    (@badincite)

    Got it needed

    <?php
    $id = 247;
    $temp = $post;
    $post = get_post( $id );
    setup_postdata( $post );
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Cant get excerpt() to appear’ is closed to new replies.