Using custom post types alongside "normal posts"
-
On my portfolio site, I originally set up my portfolio to use a custom post type called “project”. I could have added custom fields to the default post type, but I was planning to have a blog as part of my portfolio site somewhere down the line. Now that I’ve decided to start that blog, I’ve come across a somewhat unusual quirk (to me at least). I’ve used a page template called page-blog.php to display my posts and I’ve also created a page with the slug “blog” that uses page-blog.php as its template. I noticed that when I assign this blog page to be the “Posts page” in Settings > Reading Settings, no posts show up but when I unassign the page (i.e. the dropdown next to “Posts page” shows “-Select-” as the selected option) the posts show up just fine.
Contents of page-blog.php:
<?php /* Template Name: Blog Page */ ?> <?php get_header(); ?> <?php $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 5, 'caller_get_posts' => 1 ); $normal_posts = null; $normal_posts = new WP_Query($args); ?> <?php if ($normal_posts->have_posts()) { while ($normal_posts->have_posts()) : $normal_posts->the_post(); ?> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php endwhile; } ?> <?php get_footer(); ?>
- The topic ‘Using custom post types alongside "normal posts"’ is closed to new replies.