How do I add posts on a templated page used as home ?
-
Hello,
I have a wordpress website built with pages, like a classic website. It looks like the following :
– page named “home” (page_id=2) uses a template homepage.php and is set as homepage in WP prefs
– page named “misc” (page_id=3) uses a template misc.phpWhen I go to my web site, I get the content of page “home” with an url like “www.mysite.com/”. I can browse to the “misc” page and the url will be “www.mysiste.com/?page_id=3”. Note the fact that page_id is not set or displayed for the homepage as it is the cause of my problem.
Let’s say I want to display posts in each page. I add some PHP code to each template, using posts_query to retrieve the posts I want (i.e. “home” will display all posts while “misc” will display only one category). All works well until I want to page the posts displayed : e.g. I have 10 posts and I want to display 4 per page.
It works as expected on the “misc” page which is not set as homepage (I get urls like mysite.com?page_id=3&paged=2) but it doesn’t work on the “home” page. As the page_id in the url is not set (mysite.com/?paged=2 instead of mysite.com/?page_id=2&paged=2) : when displaying the previous posts I get the index.php page instead of my homepage.php template.
Any idea of how to display paged posts on a templated page set as homepage ?
Here is the code of my homepage.php template, if it can help to point out a problem :
<?php /** * @package WordPress * @subpackage Default_Theme */ /* Template Name: Homepage */ ?> <?php get_header(); ?> <div id="content" class="narrowcolumn"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <div class="entry"> <div id="homepage_text"> <?php the_content(); ?> </div> </div> </div> <?php edit_post_link('Edit this page.', '<p>', '</p>'); ?> <?php endwhile; endif; ?> <div id="blog"> <?php query_posts('showposts=4'.'&paged='.$paged); global $more; // set $more to 0 in order to only get the first part of the post $more = 0; while (have_posts()) : the_post(); ?> <div <?php post_class() ?>> <small class="blog_date"><?php the_time('l j F Y') ?></small> <h3 id="post-<?php the_ID(); ?>"><a>" rel="bookmark" title="Permalink to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3> <div class="entry"> <?php the_content('Read the full article »'); ?> </div> <p class="postmetadata"> <?php the_tags('Keywords : ', ', ', ''); ?> Published in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No comment ?', '1 comment ?', '% comments ?', 'comments-link', 'Commentaires are closed'); ?> </p> </div> <?php endwhile; ?> <div class="navigation"> <div class="alignleft"><?php next_posts_link('« Older articles') ?></div> <div class="alignright"><?php previous_posts_link('Newer articles »') ?></div> </div> <?php wp_reset_query(); ?> </div> </div> <?php /* get_sidebar(); */ ?> <?php get_footer(); ?>
- The topic ‘How do I add posts on a templated page used as home ?’ is closed to new replies.