belgin fish
Member
Posted 3 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!
<?php $recent = new WP_Query("cat=1&showposts=3");
@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.
belgin fish
Member
Posted 3 years ago #
ixi, i tried yours and its saying
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';'
belgin fish
Member
Posted 3 years ago #
also, how can i have it only show part? like when i did what dresse said, it showed the whole thing
Ohh, whoops! I overlooked that part.
@belgin fish let us know if that code works.
belgin fish
Member
Posted 3 years ago #
dresse, your works, its just it displays the whole post, how can i just display a little bit of it
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>
belgin fish
Member
Posted 3 years ago #
@belginfish, did you try ixiter's code?
belgin fish
Member
Posted 3 years ago #
ok, thanks guys it works now, lol sorry i hadnt seen your second post :p