I've created a theme with custom publish types. Among individuals publish_types is known as occasions.
I wan't to show the most recent event inside a "page" known as "approaching event". And so i produced this template file known as "Occasions". Now i have to customize the global wordpress_query to ensure that i return this last event.
This is the way my single.php appears like:
<?php get_header(); setup_postdata($post); get_page_post_content(); get_footer(); ?>
Works fine when viewing event as custom posts types "normal". Which is my template file that ought to retain the latest event:
<?php /* * Template Name: Event */ ?> <?php global $wp_query; $wp_query = new WP_Query('post_type=event&posts_per_page=1'); include 'single.php'; ?>
However this doesn't act as expected since i have produce other areas of my template based on properies like "is_single()" that is this situation returns false, because the totally known as from the page. I in some way have to set the query so individuals properies are transformed. Anybody knows how or the way i should solve this?
Put below code inside your template file.
<?php /** Template Name: Event */ get_header(); ?> <div id="content" > <?php $paged = get_query_var('paged') ? get_query_var('paged') : 1; query_posts('post_type=event&paged='.$paged.'&posts_per_page=10'); if (have_posts ()) : while (have_posts ()) : the_post(); ?> <div <?php post_class() ?>> <div class="post-title"> <h2 class="alignleft"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> </div><!-- .post-title --> <div class="post-content"> <?php the_excerpt('read more');?> </div> </div><!--end of .post_class --> <div class="post-meta"> <p class="alignright"><a class="readmore" title="<?php get_the_title();?>" href="<?php echo get_permalink( $post->ID );?>" rel="nofollow">Read</a></p> <span class="alignright comment-cnt"><?php comments_popup_link( 'No Comments', '1 Comment', '% Comments' ); ?></span> <div class="clear"></div> </div><!-- end of .post-meta --> <?php endwhile; endif; ?> </div> <div class="clear"></div> </div> <?php get_footer(); ?>