Return to Snippet

Revision: 33017
at October 5, 2010 11:04 by mike_fowler


Initial Code
<div id="featured-posts">
		<?php
			$featured_query = "
				SELECT wposts.* 
				FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
				WHERE wposts.ID = wpostmeta.post_id 
				AND wpostmeta.meta_key = 'featured'
				AND wpostmeta.meta_value = 'yes'
				AND wposts.post_type = 'post'
			";
			$featured = $wpdb->get_results($featured_query, OBJECT);
		?>
		
		<?php if ($featured): ?>
			<?php foreach ($featured as $post): ?>
				<?php //print_r($post); ?> 
				<div class="post" id="post-<?php echo $post->ID ?>">
					<a href="<?php the_permalink() ?>">
						<div class="thumbnail">
							<?php echo get_the_post_thumbnail($post->ID, 'header-thumbnail'); ?>
							<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
						</div>
					</a>
				
					<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
		
					<div class="entry">
						<?php echo $post->post_excerpt; ?>
					</div>

					<p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>  
					<?php comments_popup_link('No Comments &raquo;', '1 Comment &raquo;', '% Comments &raquo;'); ?></p>
				</div>
			<?php endforeach; ?>

		<?php else : ?>
			<h2 class="center">Not Found</h2>
			<p class="center">Sorry, but you are looking for something that isn't here.</p>
			<?php include (TEMPLATEPATH . "/searchform.php"); ?>
		<?php endif; ?>

	</div>

Initial URL


Initial Description
This can be dropped into either index.php or any custom page template to display posts in the "Featured" category.

Alternatively you could create a custom loop (loop-featured.php, for example) using this query.

Initial Title
Wordpress "Featured" Posts

Initial Tags
wordpress

Initial Language
PHP