Custom Post Type Small Help?
I have add custom post type field name 'Movies'. Now I have done these things and its working great, but the problem is, (i.e When I'm click on any movie, its showing me only one movie post, (i.e I'm click on avatar movie its showing me avatar movie post, but when I'm click on stargate movie its showing me avatar movie post. Please help its a big issue) anyone who can help me to make this code exactly which I want.
in my functions.php I have add this code:
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'Movies',
array(
'labels' => array(
'name' => __( 'movie' ),
'singular_name' => __( 'movie' )
),
'public' => true,
'has_archive' => true,
)
);
}
Then in my template file add this where I want to show post:
<?php
$args = array( 'post_type' => 'movies', 'posts_per_page' => 1 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1>
<a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark">
<?php the_title(); ?>
</a>
</h1>
<div class="entry-content">
<?php the_content(); ?>
</div>开发者_如何学Python
</div>
<?php endwhile; ?>
I'm new for this thing, so please explain me as much as you can, where I paste it or what I do?
I can't see how you structured your links to those movie-posts, but you should give them a variable, so the page where the movie-post shows up knows what to show!
e.g <a href="<?php bloginfo('url');?>/movies/showmovies.php?movie=<?php echo $moviename;?>">$moviename</a>
and in your template you modify the $args array to:
$args = array( 'post_type' => 'movies', 'posts_per_page' => 1, 'name' => $_GET['movie'] );
Should work, at least that explains why it always displays the same movie-post: Your query hast no information what movie to display, at the moment it just takes the movie-posts table and displays the first one - because of the posts_per_page limit to 1. Hope that makes sense...
精彩评论