R
R
Ruslan Makarov2016-03-03 17:36:10
PHP
Ruslan Makarov, 2016-03-03 17:36:10

How to make wordpress run default post template after if?

Good!
For some posts I use a different template, here is the code:

function single_partner() {
     if (is_single(array(891,215,3644,1055,2122,2104,1962,3702,6281,1442))) {
        return TEMPLATEPATH . '/single-partner.php';
    }
    else {
      return TEMPLATEPATH . '/single.php';
      ;}
}
add_filter('single_template', 'single_partner');

I just forced to load single.php - everything works, BUT :
- I have a custom post type and it was seduced, now it also displays single although it has its own template ...
How to fix this?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2016-03-03
@facepook

function single_partner_template( $single_template ) {
    if ( is_single( array( 891, 215, 3644, 1055, 2122, 2104, 1962, 3702, 6281, 1442 ) ) ) {
        $single_template = dirname( __FILE__ ) . '/single-partner.php';
    }
    return $single_template;
}
add_filter( 'single_template', 'single_partner_template' );

Filters always accept incoming data. You don't need to replace them entirely (in most cases), it's enough to add an exception with if, otherwise return the unchanged value.
I also corrected the formatting of the code (Coding Standards) and changed the name of the function to be more logical and understandable.
PS: And you also have an extra semicolon in line 7. Parse error and all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question