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.


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.

  • can you explain some more? whats the use case? – Bainternet Feb 3 '11 at 15:38

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.



function custom_feed_setup() {

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

function custom_feed_template($input) {

| 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 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
  • @Rarst OK. Thanks again for your valuable insight. – Bundarr Feb 4 '11 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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