Display wordpress posts on a page
written by: ryan coughlin
I have been searching for various articles and help to use WordPress to display a page full of your blog posts. I finally found out a source and it is going to be creating a custom page template in WordPress. If you want to read more on this visit: creating custom page templates.
The basic concept, will go as follows:
- Create a new file and give it a name such as “allposts.php”
- Paste the code below in the “allposts.php”
- Upload the file to your theme directory
- Create a new page in WordPress
- To the right where you see Page Template, select the one you just created
- Save and view the page. You should now be viewing your posts
The code that goes in to the “allposts.php” is below, this is an example from my site. The XHTML can be customized to the theme of your website.
The top section of code is where the name of the page template is defined. This will display on the page editor under the Page Template drop down.
<?php
/*
Template Name: Page of Posts
*/
?>
<?php get_header(); ?>
<?php
$wp_query = new WP_Query();
$wp_query->query('showposts=4'.'&paged='.$paged);
?>
<section>
<article>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<h1><?php the_title(); ?></h1>
<h5>written by: ryan coughlin</h5>
<?php the_content(); ?>
<?php edit_post_link('Edit this entry','','.'); ?>
<details>
<ul class="tags">
<?php the_category(', ') ?>
</ul>
</details>
<?php endwhile; endif; ?>
<div class="page_navigation">
<div id="p_next"><?php next_posts_link('« Read Older') ?></div>
<div id="p_previous"><?php previous_posts_link('Read Newer »') ?></div>
</div>
</article>
</section>
<?php get_footer(); ?>
<!--?php query_posts("showposts=10"); ?-->
Lastly, once this file is saved and uploaded, go to your page you created and on the right side under “Page Templates” select “Page of Posts”
To read more on the WordPress query_posts(), check out the reading.
Take a peak at some more?
-
http://nfxdesign.com Laurence