Custom blog page for a custom post type
-
Hi there,
I am trying to make a custom page template, which for custom post types I created in WordPress 3.0 beta 2 install (it is a development environment).
BACKGROUND
POST TYPES: Besides the existing post type that comes with WordPress by default (simply called post), I have created a custom post type called partner.I use the default post type post for properties (eg: houses, condos, flats, etc). These are shown everywhere on the site, where the user can browse them based on:
a) categories: (I used the default WordPress category called category that include terms such as Flat, House, Condo, etc)
b) cities: I created a custom taxonomy called city that include terms such as Madrid, Rome, New York, etc).NOTE: The custom post type called partner doesn’t appear anywhere on the site since I used the following conditionals on my index.php (see this post – thanks a lot to user julia.lasarte for her help!):
<?php //home if (is_home()) { query_posts($query_string . '&tag=featured&post_type=post&orderby=rand'); } else { query_posts($query_string.'&post_type=post&orderby=rand'); } ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> [...]
NOW FOR WHAT I DID SO FAR (which didn’t work of course :-])
1. I created a page called partners (eg: https://www.mysite.com/partners/) which I want to use to display the custom post type partner.
2. I created a page-partners.php file for the theme and it load as expected. I tested it with some PHP gibberish (such as
echo 'hello world'
and all that) and I can see that the template loads fine when I visit my /partners/ page. So no doubts that the corrected page template is loaded by the /partners/ page.3. Bearing in mind that my page-partners.php is at this point an empty page, what I tried to do next is copy and paste the contents of my index.php. However it didn’t work (by design?). Instead of returning the posts as my index.php page normally does with the posts, it returned the code in the
<?php else : ?>
statement right after the loop, which is just a basic message, like:
<div class="title"><h2>No matches have been found</h2></div>
4. What I did next is to try to play with the
query_posts()
on my page template for the /partners/ page (page-partners.php). I first I tried the code:query_posts($query_string.'&post_type=partner');
but it didn’t work. No matter what I add, subtract or if I remove thequery_posts()
from code completly, the page-partners.php template never return me any posts.SO I AM STUCK CAN SOMEONE PLEASE HELP ME? ??
As a test I changed thequery_posts()
in my index.php file and added the argumentpost_type=partner
and I got posts of type partner. So I ruled out any problems with my custom post type.Also, bearing in mind that I copy and pasted the whole index.php file inside the /partners/ page-partners.php template file and it returned the no posts found message, I am pretty sure the way I am doing it isn’t right.
Could someone please give me a hand?
Thanks in advamce
P.
- The topic ‘Custom blog page for a custom post type’ is closed to new replies.