• I have this code because I have multiple themes for different categories.

    <?php
    $post = $wp_query->post;
      if ( in_category('72') ) {
      include(TEMPLATEPATH . '/fonts.php');
      } elseif ( in_category('72') ) {
      include(TEMPLATEPATH . '/fonts.php');
      }
      if ( in_category('97') ) {
      include(TEMPLATEPATH . '/brushes.php');
      } elseif ( in_category('97') ) {
      include(TEMPLATEPATH . '/brushes.php');
      }
      if ( in_category('71') ) {
      include(TEMPLATEPATH . '/vectors.php');
      } elseif ( in_category('71') ) {
      include(TEMPLATEPATH . '/vectors.php');
      }
    else {
      include(TEMPLATEPATH . '/single2.php');
      } ?>

    I notice it is loading the last single2.php with all the pages so they’re all getting a little messed up.

    Example: https://dirt2.com/photoshop-brushes/3-in-1-skin-texture-combination-brush-pack/

    The meta titles, seem to pop up covering the regular meta tag. If you view the source it shows up at the very, very end of the document. It goes away if I delete the content of single2.php but I need it for my regular single posts.. Any help is appreciated.

Viewing 5 replies - 1 through 5 (of 5 total)
  • I’m not a php master, but it appears as if you have an orphaned “else” at the bottom of this code. That’s probably why it’s always loading the last template. Also, is there any reason that you have an if/else for each template and they are loading the same php file?

    Try this:

    <?php
      $post = $wp_query->post;
    
      if ( in_category('72') ) {
        include(TEMPLATEPATH . '/fonts.php');
      }
      else if ( in_category('97') ) {
        include(TEMPLATEPATH . '/brushes.php');
      }
      else if ( in_category('71') ) {
        include(TEMPLATEPATH . '/vectors.php');
      }
      else {
        include(TEMPLATEPATH . '/single2.php');
      } ?>
    <?php
    $post = $wp_query->post;
      if ( in_category('72') ) {
        include(TEMPLATEPATH . '/fonts.php');
      }
      elseif ( in_category('97') ) {
        include(TEMPLATEPATH . '/brushes.php');
      }
      elseif ( in_category('71') ) {
        include(TEMPLATEPATH . '/vectors.php');
      }
      else {
        include(TEMPLATEPATH . '/single2.php');
      } ?>

    How does that work?

    (edit – beaten to it I see!!)

    Thread Starter dirt2

    (@dirt2)

    Thank you both very much, my problems are gone! I knew it looked weird but didn’t know how to fix it and I really really appreciate the help, it’s nearly ruined my entire site lol.

    Alism, it’s kinda funny that we both reformatted the code the same way though. I felt a little nerdy indenting the code. ??

    Dirt2, glad it worked!

    Hehe, I am a little nerdy, so I felt no different to how I normally feel! ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Is this line of coding correct, Can someone help please?’ is closed to new replies.