WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display Part Of A New Post? (11 posts)

  1. belgin fish
    Member
    Posted 5 years ago #

    Ok, well its plain and simple.

    At the moment, i have this :

    <div class="featured">
    <?php $recent = new WP_Query("cat=1&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
    <h2>" rel="bookmark"><?php the_title(); ?></h2>
    <?php the_content(__('Read the story »'));?><div style="clear:both;"></div>
    <?php endwhile; ?>
    </div>

    <div class="featured">
    <?php $recent = new WP_Query("cat=1&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
    <h2>" rel="bookmark"><?php the_title(); ?></h2>
    <?php the_content(__('Read the story »'));?><div style="clear:both;"></div>
    <?php endwhile; ?>
    </div>

    <div class="featured">
    <?php $recent = new WP_Query("cat=1&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
    <h2>" rel="bookmark"><?php the_title(); ?></h2>
    <?php the_content(__('Read the story »'));?><div style="clear:both;"></div>
    <?php endwhile; ?>
    </div>

    </div>

    and im looking to change it so instead of only showing the post #1 from catagorie 1, it will display the 3 most recent posts.

    thanks!

  2. dressedinvalue
    Member
    Posted 5 years ago #

    <?php $recent = new WP_Query("cat=1&showposts=3");

  3. ixiter
    Member
    Posted 5 years ago #

    @dressedinvalue: I guess it shouldnt be restricted to category 1.

    I would try this ...

    <div class="featured">
    <?php
    global $wpdb;
    $sql = 'SELECT ID,post_title FROM '.$wpdb->posts.' WHERE post_password="" AND post_status="publish" AND post_type="post" ORDER BY post_modified_gmt DESC LIMIT 3';
    $result = $wpdb->get_results($sql);
    foreach($result as $row){
    ?>
    <h2><a href="<?php echo get_permalink($row->ID)" rel="bookmark"><?php echo $row->post_title ?></a></h2>
    <?php } ?>
    </div>

    I didn't test this!
    It should show the 3 most recent posts that aren't password protected.
    Maybe there is another way, than calling $wpdb directly.

  4. belgin fish
    Member
    Posted 5 years ago #

    ixi, i tried yours and its saying

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';'

  5. belgin fish
    Member
    Posted 5 years ago #

    also, how can i have it only show part? like when i did what dresse said, it showed the whole thing

  6. dressedinvalue
    Member
    Posted 5 years ago #

    Ohh, whoops! I overlooked that part.

    @belgin fish let us know if that code works.

  7. belgin fish
    Member
    Posted 5 years ago #

    dresse, your works, its just it displays the whole post, how can i just display a little bit of it

  8. ixiter
    Member
    Posted 5 years ago #

    Oops ... yea, my bad. Fixed it.
    The 2nd thing .. how much you wanna show of the post. The first x characters, the first x words?
    My code displays the first 250 chars. But this is just an example.
    Its the quick an dirty way. All HTML tags are removed. If you have a link or an image in the first 250 chars, it will not be displayed.

    <div class="featured">
    <?php
    global $wpdb;
    $sql = 'SELECT ID,post_title, post_content FROM '.$wpdb->posts.' WHERE post_password="" AND post_status="publish" AND post_type="post" ORDER BY post_date_gmt DESC LIMIT 3';
    $result = $wpdb->get_results($sql);
    foreach($result as $row){
    ?>
    <h2><a href="<?php echo get_permalink($row->ID);?>" rel="bookmark"><?php echo $row->post_title;?></a></h2>
    <?php echo substr(strip_tags($row->post_content), 0, 250 );?>
    <?php }?>
    </div>
  9. belgin fish
    Member
    Posted 5 years ago #

    nobody knows?

  10. dressedinvalue
    Member
    Posted 5 years ago #

    @belginfish, did you try ixiter's code?

  11. belgin fish
    Member
    Posted 5 years ago #

    ok, thanks guys it works now, lol sorry i hadnt seen your second post :p

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.