I found this example here of creating a custom blog post page:
1) I created a blog page under Pages > Add New 2) Under Template, I select "Blog" 3) Note that I created a blog.php file in my custom theme that has this content:
<?php /* Template Name: Blog */ ?> <?php echo "Hello World"; $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('posts_per_page=5'.'&paged='.$paged); while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
4) In settings > reading, under "Front page displays", I set "Posts page:" to "Blog"
Now I view my blog page in browser, it just renders all my posts. But it doesnt echo the "Hello World" and if I remove the code from blog.php, it has no effect! It still just renders all the posts. And then I try to add a custom query:
<?php /* Template Name: Blog */ ?> <?php global $wpdb; $content = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_type = %s LIMIT 1 ", 'header_post' ) ); echo $content->post_content; ?>
And again it ignores this and just renders all the posts with post_type of post and a post_status of publish.
Obviously, the code in my blog.php is being ignored. Why?
This is what it currently looks like too (post date is missing, comment is missing):
I made changes to the index.php in my theme:
<?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('posts_per_page=1'.'&paged='.$paged); while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
and still no effect.