Forums

Is this line of coding correct, Can someone help please? (6 posts)

  1. Dirt2
    Member
    Posted 2 months ago #

    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: http://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.

  2. monkeymynd
    Member
    Posted 2 months ago #

    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');
      } ?>
  3. alism
    Member
    Posted 2 months ago #

    <?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!!)

  4. Dirt2
    Member
    Posted 2 months ago #

    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.

  5. monkeymynd
    Member
    Posted 2 months ago #

    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!

  6. alism
    Member
    Posted 2 months ago #

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

Reply

You must log in to post.

About this Topic