Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

About this user

http://joshing.org

« Newer Snippets
Older Snippets »
1 total  XML / RSS feed 

WordPress custom post listing

// 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 &raquo;</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 '&nbsp;'; } ?></td>
                                                        <td><?php $adj = get_post_custom_values('adj_earn'); if($adj) { echo $adj[0]; } else { echo '&nbsp;'; } ?></td>
                                                </tr>
                                        <? $i++; endforeach; endif; ?>
                                
                                </table><br />
                                
                        <? endif; ?>
                        
                <?php endwhile; endif; ?>   
                </div>

<?php get_footer(); ?>
« Newer Snippets
Older Snippets »
1 total  XML / RSS feed