// This pulls out posts from WordPress and displays them on a Page Template, along with some Custom Fields.
<?php
/*
Template Name: Offerings
*/
get_header(); ?>
<div id="content" class="widecolumn">
<div id="copy">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h1>
<?php the_content('<p class="serif">Read the rest of this page »</p>'); ?>
<?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>
<? $posts = get_posts('numberposts=50&category=1');
if($posts) : ?>
<table border="0" cellpadding="5" cellspacing="0" width="100%">
<tr style="background:#cde; font-size:12pt; font-weight:bold">
<td width="40%">Description</td>
<td width="20%">Location</td>
<td width="20%">Revenue</td>
<td width="20%">Earnings</td>
</tr>
<? $i=0;
foreach($posts as $post) : setup_postdata($post);
$rev = get_post_custom_values('revenue');
$rev1 = trim($rev[0], "$");
$rev2 = str_replace(",", "", $rev1);
$revs[] = preg_replace('/ (\w* ?)?\d*/i', '', $rev2); /* strips space+words+space+digits */
$post_ids[] = $post->ID;
endforeach;
$together = array_combine($post_ids, $revs);
arsort($together);
if($together) : foreach($together as $key => $value) : get_a_post($key); ?>
<tr<? if($i % 2) { echo ' style="background:#def"'; } ?>>
<td><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></td>
<td><?php $loc = get_post_custom_values('location'); echo $loc[0]; ?></td>
<td><?php $rev = get_post_custom_values('revenue'); if($rev) { echo $rev[0]; } else { echo ' '; } ?></td>
<td><?php $adj = get_post_custom_values('adj_earn'); if($adj) { echo $adj[0]; } else { echo ' '; } ?></td>
</tr>
<? $i++; endforeach; endif; ?>
</table><br />
<? endif; ?>
<?php endwhile; endif; ?>
</div>
<?php get_footer(); ?>