Grow your CSS skills. Land your dream job.

Quick Question on WordPress/PHP conditional tags.

  • # December 19, 2010 at 2:55 pm

    Hey all,
    I have a problem and I’m sure it’s a very simple fix. I have one page of my wordpress site that needs to have a different logo image than the rest of the site. It’s working fine, except it’s also bringing in the default logo as well. I’ve been playing around with if/else statements and conditional tags, but cannot wrap my head around how to get this to work. I really don’t know any php, I’ve used just what I’ve seen from tutorials. Here is what I currently have:

    As you can see, when you are on the “STORE” template page, I need that “preemplateslogo.png” logo to display, which it is doing perfectly, but I now need to customize the rest of this code (that came with the theme I’m using). What’s happening though, is the default, regular “bloglogo.png” logo is also showing up right next to the “preemplateslogo.png” logo. How do I edit this, so that only the top statement is utilized on the “STORE” template page. I hope this makes sense to you all! Thanks!

    # December 19, 2010 at 4:33 pm

    I think adding an ‘else’ and wrapping the rest of the code should work. I think. Try:



    # December 19, 2010 at 9:51 pm

    Thank you very much for your reply. I tried it and it now throws a “Parse error: syntax error, unexpected” in the “< ?php } else { ?> line.

    # December 20, 2010 at 4:09 am

    oops, revert back for the time being, hopefully someone else will give it a go. :-)

    # December 23, 2010 at 9:49 pm

    Thanks for trying though!

    Bob
    # December 24, 2010 at 2:43 am








    The above code worked for me, although I simplified it a bit using my own images and removing the bloginfo(‘url’) and such so you should put that back. It should still work then however.

    # December 31, 2010 at 10:57 pm

    Bob! Thank you so much for your reply. Well your method kind of works, but it makes the secondary “preemplates” store logo appear on all pages of my blog. I need it to appear only on the store page. My question is this: With the $var==1 and $var==2 parts of the code. How do I assign the different logos to each of those $var’s? If I can somehow assign the logo to $var==2 for example then it will work great.

    Bob
    # January 1, 2011 at 8:41 am

    The $var==1 and $var==2 was just an example for me to be able to test it locally, ’cause if I used is_page_template(‘store.php’), it wouldn’t work for me since I obviously don’t have that page template here on my computer.

    Can you post your code like you have it now? Or did you not modify it at all? The code I posted above worked fine for me like I said, but you have to adapt it to fit your needs like I said. Thus, replace if ( $var==1 ) with if (is_page_template('store.php')) and so on.
    Basically, from what I see, the if..elseif..else statements I created should work; you just have to adapt it to your own code, so please post back what you have now.

    # January 1, 2011 at 1:18 pm

    Ok, I’m starting to understand a bit more.

    Here is where I’m at now,but I’m stuck:


    I started to adapt the code for my use, but now I don’t know what I replace $var =1; and elseif ( $var==2) with? In other words, with my original code(up at the top of this thread) I don’t have the elseif ( $var==2 ) anywhere in use. So how should I edit that?

    # January 1, 2011 at 1:20 pm

    Sorry, I’m terrible with php. I hope I’m explaining myself ok? Thanks for your time!

    Bob
    # January 1, 2011 at 1:37 pm

    Ok, check out the following code:









    I’ve adapted it so it should fit your needs exactly. I put back in your links to your images etc.
    Try this code to see if it works, and if it doesn’t, post back why it isn’t working.

    # January 2, 2011 at 2:22 pm

    Ok, I’m back. It looks like you edited the original code by adding elseif instead of just if in the line elseif ( isset($customField1[0]) ) correct? That is throwing a syntax error and the site won’t load with it added. This is crazy, haha. I figured it would be something so easy.

    Bob
    # January 3, 2011 at 7:49 am

    Can you please post the whole error it is giving?

    # January 3, 2011 at 7:49 pm

    Hey bob,
    Here is the error message: Parse error: syntax error, unexpected T_ELSEIF in /homepages/37/d221555405/htdocs/blog/wp-content/themes/aspire/header.php on line 133″ which, of course is elseif ( isset($customField1[0]) )

    # January 4, 2011 at 4:16 am

    I think you have broken the ‘if’ statement when running:

    $customField1 = get_option("theme_logo");

    Maybe set that before the main ‘if’?

Viewing 15 posts - 1 through 15 (of 23 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".