Grow your CSS skills. Land your dream job.

Extracting First Pragraph in a WordPress Post

  • # May 17, 2010 at 12:30 pm

    here’s my issue.
    for the theme we’re building we cant use the more or excerpt features in wordpress. the whole post needs to be typed into the content area as a whole.

    we created a custom loop using query posts so that the most recent post in a category, that has the tag "featured" will appear in the featured area. all other posts are just headlines until you click on the more link. when clicking on more, regardless of styling, the full post is revealed on that same page. you never go to the single.php file.

    i need to extract everything within the first "<p>" "</p>" tags, display it under the headline next to the featured post image, and then when clicking "more" NOT show it in the expanded content area. here are some screen shots.

    [img]http://img.skitch.com/20100517-brh8qmrdj8gs4imh776ejd5sfj.jpg[/img]

    [img]http://img.skitch.com/20100517-dmgwupda5ebsm4a238sntmbipj.jpg[/img]

    as you can see in the first image. the featured post is comprised of a featured image/thumb nail. date, headline and intro paragraph.

    the second image when more is clicked the whole post is revealed.

    currently that paragraph is hard coded into the theme and the latin is in the post.

    once the post cycles to the styling below it needs to behave normally. While in the featured position however the first paragraph needs to be shown under the headline, and NOT shown in the area that expands when clicking more.

    hopefully thats not too confusing and makes sense.

    if anybody has any idea how to do this i would appreciate it. i’m also not using the traditional WP loop. we’ve created our own for some of the pretty unique needs of this theme. its serving more of a CMS than blogging purpose. here’s the code i’m using:

    Code:
    < ?php
    $postcount = 0;
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts( 'paged=$page&showposts=9&tag=Featured' );
    if (have_posts()) { while (have_posts()) { the_post();
    if( $postcount == 0 ) {
    //GETS LATEST POST
    ?>

    < ?php the_time('M j') ?>

    < ?php the_title(); ?>

    < ?php if(has_tag('time-sensitive')) {?>
    < ?php the_tags('

    ‘,”,’‘); ?>
    < ?php } ?>

    This is where the first paragraph from the post will go. Currently hard coded into the WP theme for styling. Needs to extract the the first paragraph from the featured post, and not show it when clicking on more.

    More

    < ?php
    } elseif( $postcount > 0 && $postcount < = 8 ) {
    //GETS MORE EXCERPTS
    ?>

    id=”headline-< ?php echo $postcount; ?>“>

    < ?php the_title(); ?>

    < ?php if(has_tag('time-sensitive')) {?>
    < ?php the_tags('

    ‘,”,’‘); ?>
    < ?php } ?>

    < ?php
    //date image replacement prep
    $postMonth=get_the_time('M');
    $postDay=get_the_time('j');
    ?>

    day”>< ?php echo $postDay?>

    More

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".