WordPress.org

Ready to get started?Download WordPress

Forums

if Statement check validity, please (6 posts)

  1. KatGirl
    Member
    Posted 7 years ago #

    Could someone PLEASE check and confirm if I'm doing this if statement right? I seem to pull up an error, as in "unexpected ',' or ';' or something to that effect.

    <have posts... while have posts... etc..>
    <?php
    if (is_page()) {
    //which one?
    if (is_page('anthologies')) {
    echo "['hyperlink']Anthologies[/a]";
    } elseif (is_page('contemporary')) {
    echo "['hyperlink']Contemporary[/a]";
    }
    ?>

    [div]carry on with template instructions[/div]

    thanks heaps

  2. designde
    Member
    Posted 7 years ago #

    It looks like you are missing the final closing bracket see below:

    <?php
    if (is_page()) {
    //which one?
    if (is_page('anthologies')) {
    echo "['hyperlink']Anthologies[/a]";
    } elseif (is_page('contemporary')) {
    echo "['hyperlink']Contemporary[/a]";
    }
    } // Close initial if is_page
    ?>

    I doubt you need the over-arching if is_page statement though, so you could just remove it:

    <?php
    if (is_page('anthologies')) {
    echo "['hyperlink']Anthologies[/a]";
    } elseif (is_page('contemporary')) {
    echo "['hyperlink']Contemporary[/a]";
    }

    ?>

  3. KatGirl
    Member
    Posted 7 years ago #

    edit: Sorry, designde - I was writing while you were too. I will implement your changes and report back. Maybe it will fix my footer :) thanks heaps.

    Okay - update.

    I got the if statement to work (I damn near screamed my lungs out, I was so chuffed!)

    I inserted <php } ?> directly after the closing ?> and shifted The Loop to sit after that.

    Now, the only problem I seem to have is that my footer is suddeny misaligned - instead of expanding 100% (fluid design) its now only expanding to fit the content section.

    My theme is a 3 col liquid design.

    Does anyone know what ? or > or * that I'v missed?

  4. KatGirl
    Member
    Posted 7 years ago #

    No go with the footer problem.

    @designde, I removed the "over-arching" if statement and reduced the } by one and it renders beautifully!

    Thank you so much. I'm no php programmer; it took me the better part of four hours to come up with that if statement.

    Just to clarify - it holds 11 if statements in that one code. :)

    But my footer is shonkers.

  5. KatGirl
    Member
    Posted 7 years ago #

    Okay I fixed my footer problem. Just shifted the endif's to sit outside my closing content div.

    ==

    For those who don't really understand php and if statements, much like myself, this is what I did to generate a breadcrumb trail in my Pages and sub-pages. It took me the better part of four hours to figure it out. While some may snigger and smirk, because it took me so long, I feel rather proud of myself for accomplishing what was, to me, extremely difficult. I know Zip about php, other than what I've learned here @ WordPress by using the template tags and studying templates and themes.

    So in essence, four hours was nothing, right? Anyway, this is what I did.

    I created one Page = Reviews
    I created sub page= Romance
    I created 11 sub-sub pages = various sub-genres

    Reviews
    -Romance
    --anthologies
    --contemporary
    --etc...

    I wanted a breakcrumb trail that would pick up the "category" name of my sub-sub pages, as well as the title of my Page.

    Because I don't know that much about php or if or is satements... I hand coded the first part of my breadcrumb trail into my template to cover the inital bc link trail:

    Home
    Reviews (main Page category)
    Romance (first sub-category)

    Then I created a If Statement to find the category name of the first Sub-Sub-Page = Anthologies. I duplicated that if statement to also find, if applicable, the category name of any other Sub-Sub-Page category of Reviews/Romance (main parent/s) when viewing a page post.

    I inserted the <?php the_title(): ?> tag at the end, so bascially my breadcrumb trail looks like this:

    Home || Reviews || Romance || Anthologies || Dark Warrior (title of page/post)

    The good thing about this, and the if statement, is that I made a Review template (main Page cat) and left it blank at this point (this will eventually display current month reviews as link list). I also created Romance Template (first Sub Page Cat, which is also presently blank but will also eventually display top 10 links for each sub-genres as teasers) and finally, I made one generic template Sub-Genre for ALL sub-sub page posts.

    And Voila.

    One fully functional working "Category" breadcrumb trail. If anyone has a better way of doing this, I will be greatly interested.

    K

  6. KatGirl
    Member
    Posted 7 years ago #

    Just advising...

    I've somehow ruined this - don't know how, & I especially don't know what, exactly, I ruined, but the if statement no longer displays the name of my Page.

    After fiddling with it for too many hours, I'm going to change strategies.

    If someone has any advice as to how to effectively use the If statement inside a Page Template like such:

    if (is_page('page-1')) {
    echo "[hyperlink/page-1]LINK[/a]";
    elseif (is_page('page-2')) {
    echo "[hyperlink/page-2]LINK[/a]";
    }
    ?>

    Page categories:
    Page 1
    -Page 2

    I will be forever in your debt.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags