WordPress.org

Ready to get started?Download WordPress

Forums

WP Query and Snippet Problems... (5 posts)

  1. wheelcipher
    Member
    Posted 6 years ago #

    Hello ..

    I am creating a front page that will show snippets of my posts. I almost have it working right, but not quite. What I have is:

    <?php $recent = new WP_Query("cat=24&showposts=3"); while($recent->have_posts()) : $recent->the_post();?>

    (This line is supposed to show the first three posts from category 24...almost works right. it shows 3 posts, but the first one is messed up... see below.) Then I have:

    <b>" rel="bookmark"><?php the_title(); ?></b>

    (Pulls up the title, etc... This works OK)

    <?php the_content_limit(200, ""); ?>

    (This line limits the number of characters in the snippet, and works fine)

    What I get with the above query is:

    The title of the last story posted in category 24 is fine (as the subject of the snippet), but the text of the snippet comes from my very last post (no matter what category it was put in)

    After I get past this one glitch, all the other stories are fine. I just have the title/snippet problem. If anyone can help, I would appreciate it.

  2. BPartch
    Member
    Posted 6 years ago #

    Can you do it with the Loop?

    <?php if (have_posts()) : ?>
    
    <?php query_posts('cat=24&showposts=3'); ?>
    
    <?php while (have_posts()) : the_post(); ?>
    
    <b><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></b>
    
    <?php the_content_limit(200, ""); ?>
    
    <?php endwhile;?>
    
    <?php else : ?>
    
    <?php include (TEMPLATEPATH . '/404.php'); ?>
    <?php endif; ?>

    I am not familiar with the_content_limit(), but you say it is working so... If this does not help, post again and I or someone smarter than me will help you figure it out. :)

  3. wheelcipher
    Member
    Posted 6 years ago #

    That works great!!! Thanks!

    My only other question is: Is there a similar routine/loop that I can do to pull the last x posts (no matter what vategory they were filed under?)

  4. BPartch
    Member
    Posted 6 years ago #

    Hello

    Assuming you want it to display the same as above just alter the query_posts line:

    <?php query_posts('showposts=x'); ?>

    x = the number of posts you want to display

  5. wheelcipher
    Member
    Posted 6 years ago #

    !@#$%^&* perfect! Thanks a million!!

Topic Closed

This topic has been closed to new replies.

About this Topic