Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Can I create a template and load it without associating a page/post to it in WordPress? The template will list custom posts in XML.

[update]

I have a jquery carousel that loads an XML file through ajax. I am storing each slide as a custom post type call 'carousel_slide'. I want to create an XML feed with these custom post types.

At first I created the feed outside wordpress, including wp-load.php and using WP_Query. This worked fine but I now realize that I need a multi-lingual plugin (WPML) to be loaded as well. This is why I want to create a wp template instead. However if I create a template, I need to assign a page to it to be able to load it. I'd rather not create an empty page simply to be able to call a template.

I am new to WordPress development and might have overlooked an obvious solution.

share|improve this question
    
can you explain some more? whats the use case? –  Bainternet Feb 3 '11 at 15:38
add comment

1 Answer

up vote 2 down vote accepted

The basic answer - you can easily load template (or any PHP file really) with *drumroll*load_template(). :)

As for best way to implement your custom feed, I think it would make sense to do it by analogue with native WP feeds. You register feed name and handler function with add_feed() and load template in that handler.

Example:

add_action('init','custom_feed_setup');

function custom_feed_setup() {

    add_feed('custom-post-type-xml', 'custom_feed_template');
}

function custom_feed_template($input) {

    load_template('whatever');
}
share|improve this answer
    
Ok, but what would be the URI to the feed? That's what I'm having trouble understanding ... Can I setup something like domain.com/custom-post-type-xml/ ? –  Bundarr Feb 3 '11 at 18:35
    
@Bundarr I think it would be something like domain.com/?feed=custom-post-type-xml or domain.com/feed/custom-post-type-xml –  Rarst Feb 3 '11 at 19:05
    
@Rarst Thanks ! –  Bundarr Feb 3 '11 at 20:40
    
@Rarst What is the use of $input param? Also, where does one get acquainted with these techniques? Nothing much online to explain add_feed(). –  Bundarr Feb 4 '11 at 13:54
    
@Bundarr just a leftover, WordPress passes if that is generic feed or comments feed in it. You can get rid of it by hooking with specifying to pass zero arguments, as for me that is slightly more messy than just leaving it there. Unfortunately add_feed() is very poorly documented in Codex, so your options are looking through source code, googling some more and asking questions here. :) –  Rarst Feb 4 '11 at 13:59
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.