Forums

[resolved] the_excerpt() (4 posts)

  1. therealhopeful
    Member
    Posted 2 years ago #

    According to the codex documentation the_excerpt() API will automatically strip HTML tags under certain conditions. However, I cannot seem to get it to work. Here is my code:

    <?php while (have_posts()) : the_post(); ?>
            <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php echo strip_tags( the_excerpt() ); ?>" alt="<?php echo strip_tags( the_excerpt() ); ?>"><?php the_title(); ?></a></h1>
          <?php endwhile; ?>

    If you go to this link and hover your mouse over the headings, you will see what I am talking about.

    How do I get the_excerpt to strip the HTML tags?

    Thanks! :D

  2. Trent
    Member
    Posted 2 years ago #

    Doesn't that work if you are called the_excerpt() and not using the conditional of it while called the_post(). Anyone?

    Trent

  3. therealhopeful
    Member
    Posted 2 years ago #

    Thanks for the suggestion, Trent, but it's no-go. I tried both of the following bits of code, and they ended up generating an endless loop:

    <?php while (have_posts()) : ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php echo strip_tags( the_excerpt() ); ?>" alt="<?php echo strip_tags( the_excerpt() ); ?>"><?php the_title(); ?></a></p>
          <?php endwhile; ?>
    <?php while (have_posts()) : the_excerpt(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php echo strip_tags( the_excerpt() ); ?>" alt="<?php echo strip_tags( the_excerpt() ); ?>"><?php the_title(); ?></a></p>
          <?php endwhile; ?>

    Any other thoughts? :)

  4. therealhopeful
    Member
    Posted 2 years ago #

    Issue resolved! :D

    There's a hidden API that does the job:

    get_the_excerpt()

Topic Closed

This topic has been closed to new replies.

About this Topic