• Hi there,

    I’m trying for quite some time to make a excerpt, the thing is that not only get the summary out, but it all goes.

    Attachment part of my code, so you can see where I got the error.

    $leidoPages = get_posts(array('orderby' => 'post_date', 'order' => '100', 'post_type' => 'leido', 'posts_per_page' => 3));
    
    <section onclick="window.location = '<?= get_permalink($leidoPage->ID); ?>' id="leidosBanners" class="cf">
            <?php $counter = 0; foreach ($leidoPages as $leidoPage): ?>
                <?php if($counter == 0 || $counter == 1): ?>
                    <div class="columns sixteen leidosBanner">
                        <?php $leidoImage = get_leido_image($leidoPage->ID, array(940, 320)); ?>
                        <a href="<?= get_permalink($leidoPage->ID); ?>">
                            <?= $leidoImage['image']; ?>
                             <div class="textoleido">
                                 <?= apply_filters('the_content', $leidoPage->post_content); ?>
    
                               </div>
                        </a>
                <?php elseif ($counter > 1 && $counter < 4): ?>
                    <div class="columns sixteen leidosBanner">
                        <?php $leidoImage = get_leido_image($leidoPage->ID, array(460, 170)); ?>
                        <a href="<?= get_permalink($leidoPage->ID); ?>">
                            <?= $leidoImage['image']; ?>
                            <div class="textoleido">
                                 <?= apply_filters('the_content', $leidoPage->post_content); ?>
                               </div>
                        </a>
                    <?php endif; ?>
                    </div>
            <?php $counter++; endforeach;?>
        </section>
Viewing 2 replies - 1 through 2 (of 2 total)
  • You could try running your posts through setup_postdata() and then using the_excerpt() to render it in your template. So:

    <?php foreach( $leidoPages as $leidoPage ): setup_postdata( $leidoPage );
      if(...): ?>
        <div class="columns sixteen leidosBanner">
          <a href="<?php the_permalink();?>"><?php echo $leidoImage['image'];?>
              <div class="textoleido"><?php the_excerpt();?></div>
          </a>
        </div>

    You get the idea. There’s some useful information in the codex for get_posts().

    A quick fix would be to apply the filter get_the_excerpt instead of the_content to your post_content.

    So

    <?= apply_filters('the_content', $leidoPage->post_content); ?>

    should be:

    <?php echo apply_filters('get_the_excerpt', $leidoPage->post_content); ?>

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Problem with excerpt on Custom Post Types’ is closed to new replies.