Get the 5 lastest Featured Posts from a category

Here is the website http://ariadneswonderland.gr/ that all this concerns.

On the homepage I’m using a Drop shadow box plugin
under the gallery to show a series of images of featured posts, as of right now, as i’m still building the website all you see is the White box under the gallery and a emoticon inside it..

Read More

What i’d like is to be able to do is have some code that pulls the 5 lastest posts from a category (in this case frontpage id 7) and Displays the Featured Post Image next to each other.

Code:

=============

= X X X X X =

Where X is a Featured post image automatically retrieved instead of having to retrieve and add links every time i want to change a feature.
= is the automatically generated [dropshadowbox].

Any ideas/code/snipets/plugins that you might feel would work would be greatly appreciated.

So far however all i’ve come up with is this but I can’t figure out how to implement the php into the post, phpexec and similar plugins don’t seem to work for this, tho simple things like echo test; work fine. And making it a function doesn’t work as it doesn’t seem to return anything :S Obviously I need alot more coding experience but as of right now I’d like to just be done with this website.

PHP Code:
// fetching latest posts from specific category 
$categoryId = 7; 
$args = array('category' =>  categoryId  , 'post_status' => 'publish', 'numberposts' => 5); 
$posts = get_posts( $args ); 
foreach($posts as $post){ 
$feat_image_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); 
$post_url = get_permalink($post->ID); 
}  

Related posts

Leave a Reply

2 comments

  1. <?php /* Set the name of the category and the number os posts to be displayed */?>
    <?php $first_query = new WP_Query('category_name=name&posts_per_page=7'); ?>
    <?php /* Show the posts */ ?>
    <?php while ($first_query->have_posts()) : $first_query->the_post(); ?>
        <?php  /* Make the hiperlink to the post */ ?>
        <a href="<?php the_permalink(); ?>">
            <?php /* Get the featured post image */ ?>
            <div class="post-image"> <?php /* This div is just for help you to organize your posts images */ ?>
                <?php the_post_thumbnail(); ?>
            </div>
        </a>
    <?php endwhile; // End the loop. Whew. ?>
    

    In the second line, chose the name of the category, and the number of posts that will be displayed in this page. The function get the featured post image and insert into your webpage.

  2. i suggest you use that code in the .php file itself. if its a page with a unique template, change that template file.

    if not, edit the page.php ( or single.php ) and add a conditional for the home page id and include your code.

    i didn’t test your code but if its correct something like this would work:

    if ( get_the_ID() == '99' ) {
       // your code
    }