<?php
/**
* @package WordPress
* @subpackage Default_Theme
*/
/*
Template Name: listorderbycustom
*/
/*
Author: Mac McDonald
Contact at BluegrassMiataClub.com using About->Contact Us form.
This program selects posts in a specified category,
ordered by date within the presence of a specified Custom Field,
i.e. those having the CF will be listed first.
Set the following variables to your needs:
*/
$meta_key = 'URL';
$catname = 'Hotel';
add_filter('posts_fields','mam_posts_fields');
add_filter('posts_join','mam_posts_join');
add_filter('posts_orderby','mam_posts_orderby');
$paged = (isset($_GET['paged'])) ? intval($_GET['paged']) : 1;
?>
<?php get_header(); ?>
<div id="content" class="narrowcolumn" role="main">
<?php
$mam_global_fields = 'wpmeta.meta_value, if (isnull(wpmeta.meta_value),1,0) as sorturl';
$mam_global_join = "LEFT JOIN $wpdb->postmeta wpmeta ON
({$wpdb->posts}.ID = wpmeta.post_id AND wpmeta.meta_key = '$meta_key')";
$mam_global_orderby = 'sorturl';
query_posts("category_name=$catname&caller_get_posts=1&paged=$paged");
echo "<h2>Posts in Category $catname</h2><br />";
?>
<?php if (have_posts()) : echo '<ul>' ?>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li><br />
<?php endwhile; ?>
<div class="navigation">
<div class="alignleft"><?php next_posts_link('« Older Entries') ?></div>
<div class="alignright"><?php previous_posts_link('Newer Entries »') ?></div>
</div></ul>
<?php else : ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php get_search_form(); ?>
<?php endif; ?>
</div><!-- End content -->
<?php get_footer(); ?>
<?php function mam_posts_fields ($fields) {
global $mam_global_fields;
return "$fields, $mam_global_fields";
}
function mam_posts_join ($join) {
global $mam_global_join;
return "$join $mam_global_join";
}
function mam_posts_orderby ($orderby) {
global $mam_global_orderby;
return "$mam_global_orderby, $orderby";
}?>