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.

I need to know: I have wrote at 60% one plugin, it works well in backend (some settings, some cpt, some custom fields... nothing special). It uses custom post type with custom fields.

For now I need to change default archive category behaviour as well as change behaviour of single posts of this CPT _doesn't_touching_ templates (because this plugin will be used not only in the 1 site and there will be many templates).

Just programmatically, by filters/actions - change it as I like.. for example, I will need to show up this custom fields in this single custom post type.

Does somebody knows about how to do it by plugin?

share|improve this question
2  
Could you provide some concrete examples? I am not sure I understood what you want to achieve. –  toscho Oct 7 '12 at 22:54
1  
Okay, let's see if this sounds right: you want to be able to programmatically display the custom fields and types on the front end using plugin files instead of theme files? I know the Organize Series plugin does this. I can dig through its code if that's the kind of thing you're looking for. –  Liana Mir Oct 9 '12 at 17:30
add comment

1 Answer

You can use templates located within your plugin instead of theme files, like so:

add_filter('archive_template', 'redirect_to_plugin_archive_template');
function redirect_to_plugin_archive_template($template) {

    if(is_post_type_archive('my_cpt')) {
        return dirname(__FILE__) . '/templates/my_archive_template.php';
    }
}

add_filter('single_template', 'redirect_to_plugin_single_template');
function redirect_to_plugin_single_template($template) {

    if(is_singular('my_cpt')) {
        return dirname(__FILE__) . '/templates/my_single_template.php';
    }
}

Obviously you need to change the custom post type slug and the template paths, but that's the general idea.

share|improve this answer
add 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.