WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Post title link to a different template?

[Resolved] Post title link to a different template?

  • Hello guys,

    I’ve managed to have a separate theme for each category using WP’s hierarchy method (cat=1 with category-1.php and so on). The problem is, each time I clicked the post title link, it always goes to the default index.php template.

    How can I make a post title on cat=1 link to category-1.php instead of index.php?

    Thank You

Viewing 8 replies - 1 through 8 (of 8 total)
  • See this post (and following replies in thread) for a plugin I wrote that lets you assign category templates to posts in that category:

    http://wordpress.org/support/topic.php?id=27821#post-156289

    There is also a solution in this thread:
    http://wordpress.org/support/topic.php?id=29434#post-173621
    Check out the poster’s website, the template/style is working even on single post views.

    I don’t know Kafkaesqui, your plugin (after activated) showed this error on my admin session:

    Warning: Cannot modify header information – headers already sent by (output started at /home/starnews/public_html/coba/wp-content/plugins/post-templates-by-cat.php:40) in /home/starnews/public_html/coba/wp-admin/admin.php on line 6

    Warning: Cannot modify header information – headers already sent by (output started at /home/starnews/public_html/coba/wp-content/plugins/post-templates-by-cat.php:40) in /home/starnews/public_html/coba/wp-admin/admin.php on line 7

    Warning: Cannot modify header information – headers already sent by (output started at /home/starnews/public_html/coba/wp-content/plugins/post-templates-by-cat.php:40) in /home/starnews/public_html/coba/wp-admin/admin.php on line 8

    Warning: Cannot modify header information – headers already sent by (output started at /home/starnews/public_html/coba/wp-content/plugins/post-templates-by-cat.php:40) in /home/starnews/public_html/coba/wp-admin/admin.php on line 9

    @moshu: I believe she (it’s a she right?) is using a different design method than what I’m doing now. I think her site is only manipulating the header with the include function while in my case, I put the whole site into a new design, not just the header.

    ozzie123: I recently did some work with a multi-theme WP site. I put code similar to the example below into a plugin. Your theme-switching criteria and template names will be different, so I’ll leave those parts blank.
    if ([criteria]) {
    add_filter('template','specialTemplate');
    add_filter('stylesheet','specialTemplate');
    function specialTemplate($template) {
    $template = [dirname of template];
    return $template;
    }
    }

    I’m assuming that I have to change ‘template’, ‘stylesheet’, and ‘specialTemplate’ right? To what should I suppose to do that? You know, I’m quite a newbie on PHP subject.

    However, I do found this single script that works. I got it from http://www.cameraontheroad.com/?p=623 and the script looked like:

    <?php
    $post = $wp_query->post;
    if ( in_category(‘9’) ) {
    include(TEMPLATEPATH . ‘/single9.php’);
    elseif ( in_category(’12’) ) {
    include(TEMPLATEPATH . ‘/single12.php’);
    elseif ( in_category(’42’) ) {
    include(TEMPLATEPATH . ‘/single42.php’);
    } else {
    include(TEMPLATEPATH . ‘/single1.php’);
    }
    ?>

    The problem is, I kept getting this error:
    Parse error: parse error, unexpected $ in /home/starnews/public_html/coba/wp-content/themes/starnews/single.php on line 14

    Can anyone help out here?

    I figure that I should make a new single.php everytime I wanted to reffer them to a new page. For example, for single.php I would putt:

    <?php
    $post = $wp_query->post;
    if ( in_category(‘1’) ) {
    include(TEMPLATEPATH . ‘/category-1.php’);
    } else {
    include(TEMPLATEPATH . ‘/single1.php’);
    }
    ?>

    And when I clicked category2, the script will include single1.php. To ‘redirects’ it to category-2.php, I make this line on single1.php:

    <?php
    $post = $wp_query->post;
    if ( in_category(‘2) ) {
    include(TEMPLATEPATH . ‘/category-2.php’);
    } else {
    include(TEMPLATEPATH . ‘/single2.php’);
    }
    ?>

    And so on. I hope this will help PHP newbies just like me. Cheers

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] Post title link to a different template?’ is closed to new replies.
Skip to toolbar