Hi,
I've created a custom post type called "slides" and I try to display the content in my header.
I could use views to do it but I also would like to know how to do it with PHP?
I'm using this code but it doesn't work :
<?php query_posts('post_type=slides&posts_per_page=4'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
....
Thank you
Hi Benoit,
I have a similar code that works:
<?php
/** save the original query **/
$orig_query = $wp_query;
$args = array(
'post_type' => 'slides',
'post_per_page' => 4
);
$wp_query = new WP_Query($args);
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) :
$wp_query->the_post();
endwhile;
endif;
** restore original query **/
$wp_query = $orig_query; wp_reset_query();
?>
You can see it in action here hidden link
It's still in development so some design glitches may occour 😀
I hope this helps
Forgot to add - the $wp_query->the_post(); prepares the $post objects so You can use the the_post_thumbnail(), and other wp stuff there