sticky
closedrecently updated posts
<?php
$today = current_time('mysql', 1);
$howMany = 5; //Number of posts you want to display
if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $howMany")):
?>
<h2><?php _e("Recent Updates"); ?></h2>
<ul >
<?php
foreach ($recentposts as $post) {
if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
echo "<li >ID)."'>";
the_title();
echo '</li >';
}
?>
</ul >
<?php endif; ?>
query using custom fields outside the loop
<?php $quote = get_posts('post_type=page&showposts=1&meta_key=quote&orderby=rand'); foreach($quote as $post) : setup_postdata($post); ?>
< li class="quote">< a href="<?php the_permalink(); ?>" title="Read the <?php the_title(); ?> case study"><?php echo get_post_meta($post->ID, "quote", true); ?>
<em ><?php echo get_post_meta($post->ID, "quote-author", true); ?></em ></li >
<?php endforeach; ?>
$quote -- name of function post_type=page -- remove to query posts orderby=rand -- random order showposts=1 -- limit to 1 post
effect -- displays 1 random custom excerpt outside of the loop
Latest Posts from Category
<div class="pod">
<h2>Latest News</h2>
<ul >
<?php query_posts('cat=CAT ID&showposts=NUMBER'); ?>
<?php while(have_posts()) : the_post(); if(!($first_post == $post->ID)) : ?>
<li >
< a href= "<?php the_permalink() ?>" rel="bookmark" title="Permalink: <?php the_title(); ?>"><?php the_title(); ?>
</li >
<?php endif; endwhile; ?>
</ul >
</div>
If In Category
<?php if (in_category('YOUR CATNAME')) : ?>
<div class='eventinfo'>
<h2>Event Details</h2>
<?php the_meta(); ?>
</div>
<?php endif; ?>
query post for a specific page
<?php $contact_drop = new WP_Query('pagename=contact'); while ($contact_drop->have_posts()) : $contact_drop->the_post(); $do_not_duplicate = $post->ID; ?>
<div id="contact-slide">
<h3 class="page-page-title"><?php the_title(); ?></h3>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
custom templates for posts
function custom_template($template) {
global $wp_query;
$cats = get_the_category($wp_query->post->ID);
$cat = $cats[0];
if (file_exists(TEMPLATEPATH."/category-".$cat->cat_ID.'.php')) {
return TEMPLATEPATH."/category-".$cat->cat_ID.'.php';
}
return $template;
}
add_filter('single_template', 'custom_template');
load jquery within header to use
<?php wp_enqueue_script('jquery'); ?>
if custom field else
<?php
$number = get_post_meta($post->ID, 'number', true);
if ( $number ) {
echo 'there is a custom field value';
}
else {
echo 'no custom field value';
}
?>
This topic has been closed to new replies.