• Hi,

    I need some help with some php and html tweak in the header.php.

    I want to Pull 3 Most Recent Article from a certain catergory, and display its title and thumbnail (custom fields) and post it onto the header.

    I just want to add a featured post section in the header, and I want to do so with some simple code in the header.php file. I want to achieve that Wired.com frontpage look, where above the Navigation Bar, theres a couple of featured post with thumbnails. Being a complete PHP novice, I had no idea how to do it so I googled for some tutorial, and luckily, I found a few and tried 2 that worked. Basically, I inserted the following code right before the horrizontal navBar. Here comes the problem:

    In the end result, one of the tried code only has a thumbnail and no title text, while the other one has no thumbnail, but has the title text.

    Code With Just the Thumbnail:

    <div id="featured">
    	<ul id="carousel">
    		<?php
    		$featured_posts = get_posts('numberposts=3&category=1');
    
    		foreach( $featured_posts as $post ) {
    			$custom_image = get_post_custom_values('featured_image', $post->ID);
    			$image = $custom_image[0] ? $custom_image[0] : get_bloginfo("template_directory")."/images/no-featured-image.jpg";
    			printf('<li><a href="%s" title="%s"><img src="%s" alt="%s" /></a></li>', get_permalink($post->ID), $post->post_title, $image, $post->post_title);
    		}
    		?>
    	</ul>
    	<div class="clear"></div>
    </div>

    Code With the Title Text:

    <div id="featured">
    
    <?php query_posts('cat=1&showposts=5'); ?>
    	<ul>
    	  <?php while (have_posts()) : the_post(); ?>
    	  <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
    	  <?php endwhile;?>
    	</ul>
    </div>

    again, what I want is straightforward:

    To Pull 3 Most Recent Article from a certain catergory, and display its title and thumbnail (custom fields) both linked to the article and post it onto the header.

    How Do I do it?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Add a featured Section on the Header’ is closed to new replies.