Link to home
Start Free TrialLog in
Avatar of mandi224
mandi224Flag for United States of America

asked on

List Pages by Custom Field - Formatting first 2 differently?

I'm using the code below (plus the Advanced Custom Fields plugin) to get a listing of sub-pages within events and list them on the homepage of my WordPress site.

There are about 12 pages that are returned, and I want to list them all -- but for the FIRST THREE in the list, I want to display a thumbnail image and apply some different styling. How can I modify the foreach loop (?) to style posts 1, 2, and 3 differently and then display the remaining 9 events styled how they are below?

	$querystr = "
	SELECT * FROM $wpdb->posts
	LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
	LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
	LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
	WHERE $wpdb->posts.post_status = 'publish'
	AND $wpdb->postmeta.meta_key = 'date'
	ORDER BY $wpdb->postmeta.meta_value ASC
	$pageposts = $wpdb->get_results($querystr, OBJECT);

<?php if ($pageposts): ?>
	<?php global $post; ?>
	<?php foreach ($pageposts as $post): ?>
	<?php setup_postdata($post); ?>
		<div class="clearfix">
		<div class="event_listing clearfix" id="post-<?php the_ID(); ?>">
			<span class="event_date"><?php $key="date"; echo get_post_meta($post->ID, $key, true); ?></span>
			<span class="event_title"><a href="/test/events/#<?php the_ID(); ?>" rel="bookmark" title="Permalink"><?php the_title(); ?></a></span>
			<span class="event_location"><?php $key="location"; echo get_post_meta($post->ID, $key, true); ?></span>
	<?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 endif; ?>

Open in new window

Avatar of Ovid Burke
Ovid Burke
Flag of Saint Vincent and the Grenadines image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial