Wordpress Coding Help

Associate
Joined
23 Jun 2007
Posts
552
Location
South East
Evening all,

Right what I'm trying to do is have 3 set posts as 'featured content' on my main page. I've added them all to the same category in wordpress.

If I create a 4th post it bumps them along and adds my latest post to the 'featured' content. (Even though I didn't add it to the category)

In this code I'm guessing i have to specify that only a certain category will display at the top and all other posts go into 'latest posts' - but i don't know how :p

<?php get_header(); ?>

<div id="featured">
<h2>Featured</h2>
<!-- Edit Below -->
<?php query_posts('cat=ID&showposts=2'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="front-post">
<div class="featured-post">
<div class="featured-title">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?>
</a></h2>
</div>
<div class="featured-image">
<?php image_attachment('image', 303, 231); ?>
</div>
</div> <!-- END Featured-post -->
<div class="postMeta-featured"><span class="date"><?php the_time('F j, Y') ?></span><span class="comments"><?php comments_popup_link('0', '1', '%'); ?></span></div> <div class="clear"></div>
<div class="featured-content">
<?php the_excerpt(); ?>
<p class="moretext"><a href="<?php the_permalink() ?>">Continue Reading...</a></p>
</div> <!-- END Featured-Content -->
</div>
<?php endwhile; ?>
<!-- Edit Below 2 -->
<?php query_posts('cat=ID&showposts=1&offset=2'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="front-post-last"> <!-- Featured-Last -->
<div class="featured-post">
<div class="featured-title">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?>
</a></h2>
</div>
<div class="featured-image">
<?php image_attachment('image', 303, 231); ?>
</div>
</div> <!-- END Featured-post -->
<div class="postMeta-featured"><span class="date"><?php the_time('F j, Y') ?></span><span class="comments"><?php comments_popup_link('0', '1', '%'); ?></span></div> <div class="clear"></div>
<div class="featured-content">
<?php the_excerpt(); ?>
<p class="moretext"><a href="<?php the_permalink() ?>">Continue Reading...</a></p>
</div> <!-- END Featured-Content -->

</div>
<?php endwhile; ?>
</div> <!-- END Featured -->
<div class="clear"></div>
<div id="front-bottom">
<div id="latest-wrap">
<h2>Latest Posts</h2>
<div class="content">
<!-- Edit Below 3 -->
<?php query_posts('cat=-ID&showposts=8'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="latest-post-wrap">
<div class="latest-post">
<div class="latest-title">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?>
</a></h2>
</div>
<div class="latest-image">
<?php image_attachment('image', 162, 118); ?>
</div>
</div>
<div class="latest-content">
<div class="postMeta-front"><span class="date"><?php the_time('F j, Y') ?></span><span class="comments"><?php comments_popup_link('0', '1', '%'); ?></span></div> <div class="clear"></div>
<p><?php
$excerpt = get_the_excerpt();
echo string_limit_words($excerpt,30);
?></p>
<p class="moretext"><a href="<?php the_permalink() ?>">Continue Reading...</a></p>
</div>
</div>
<?php endwhile; ?> <!-- END -->
</div>
<div class="clear"></div>
</div>
<?php get_sidebar(); ?>
<div class="clear"></div>
</div>
<?php get_footer(); ?>

I assume its the line in bold.

Any ideas chaps? :o


EDIT

I've realised I was too quick to post..

I've changed this line '<?php query_posts('cat=ID&showposts=2'); ?>' to '<?php query_posts('cat=featured cat id&showposts=2'); ?> in all 3 instances. But now only featured posts display, even in latest posts.

Im guessing there must be a ('showposts=latest') or something similiar. Off to google..
 
Last edited:
I use this bit of code to separate posts in the blog and portfolio categories of my site and put them on the relevant page.

Code:
query_posts('category_name=Featured');

Put it just before "the loop" and it works a treat for me. Not entirely sure if this is what you're after but hopefully it'll be of some help :)

So for your site, if you just keep only 3 posts in the featured category and swap the code you've highlighted with mine it should work... I think :p

Have you got a link or screen shot of your site so we can have a better idea of what you're after?
 
Last edited:
I use this bit of code to separate posts in the blog and portfolio categories of my site and put them on the relevant page.

Code:
query_posts('category_name=Featured');

Put it just before "the loop" and it works a treat for me. Not entirely sure if this is what you're after but hopefully it'll be of some help :)

So for your site, if you just keep only 3 posts in the featured category and swap the code you've highlighted with mine it should work... I think :p

I'm getting there.. I now know how to only show featured in the first few posts. But I'm a little confused as to what to do with this line.

<?php query_posts('cat=ID&showposts=8'); ?>

Its the last line i need to look at. I basically need to say 'retrieve all recent posts excluding those in featured category'
 
I'm not sure if this would work as I've never tried it, but maybe you could have a go.

Code:
query_posts('category_name=category1, category2, category3, etc');

Just don't include the featured category? I've not tested this btw as I only just got your reply and I'm now off to cook dinner :D

Good luck with it for now.
 
Back
Top Bottom