• Resolved Alex Cragg

    (@epicalex)


    im currently implementing an online shop and i want a new sidebar to display how far through the order process the customer is. Ive done this by creating some if statements in the new sidebar, but at the moment, i cant get this to work with putting in an unordered list.

    It works fine if i call a function, such as wp_list_pages, but i cant work out how to tell it to just display what i put, rather than tell it to perform a function.

    any pointers?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Alex Cragg

    (@epicalex)

    *your free bump for the day*

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Bumping doesn’t help when nobody understands what you’re talking about in the first place.

    What exactly are you trying to do? Get the current page name? You’ll have to be more specific, because I have no idea what it is that you need to know.

    Thread Starter Alex Cragg

    (@epicalex)

    haha, fair enough, i read it through and thought it made sense but then it would to me wouldn’t it. and anyway, the bump got your attention ??

    so i have a new sidebar, that is called when on any page that is in my new Shop template. The shop template is applied to 4 separate Pages, and therefore on each of those Pages the new sidebar is called.

    In that sidebar i want to show an unordered list of four items that i write in myself. Each list item will have a class of, for example, ‘yes’ or ‘no’. In my css all of the times where a yes class is shown a tick will be output next to the list item. if it is no then the tick will not be there.

    so the list will need to be different depending on what p
    Page you are on, as it is showing how far through the order process you are.

    for the first page, where none of the list items will have the class yes, as nothing has been done, it will look like this.

    <ul>
    <li class="no">First Item</li>
    <li class="no">Second Item</li>
    <li class="no">Third Item</li>
    <li class="no">Fourth Item</li>
    </ul>

    As you progress though the shop, to the checkout and transaction results page etc, the list needs to be different. like so for example:

    <ul>
    <li class="yes">First Item</li>
    <li class="yes">Second Item</li>
    <li class="no">Third Item</li>
    <li class="no">Fourth Item</li>
    </ul>

    you get the picture.

    So to decide which list to display, and instead of having a different sidebar for each Page of the Shop template, i wanted to create a series of if statements.

    The only problem is that i get a parse error saying unexpected < etc when i put the list i created in the if statement straight up. So i would like to know how to display the contents of the if statement, rather than just using it to perform a function.

    I know that the if statement is correct, cause as i said i can get functions to be performed such as wp_list_pages. But as there is no function for what i want, this working is no use to me.

    I hope ive explained what i want better now?

    I know that there is another solution to this, and that is to create different sidebars, and include an if statement in the Shop template to decide which one to display, but i dont want to have to create all the extra files if i can avoid it.

    thanks otto, hope you can help

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.ads-software.com Admin

    Oh. You want to include html inside the if statement. No problem.

    PHP can be toggled on or off at any time. Examine this:

    <?php do_some_function(); ?>
    normal html here
    
    <ul><li>blah!</li></ul>
    <?php more_php_code(); ?>

    The gist of it is that PHP code must be enclosed in <?php … ?> tags. Anything outside those tags is HTML. However, PHP processing still applies. So this works too:

    <?php if (is_page('whatever')) { ?>
    <ul><li>page whatever!</li></ul>
    <?php } ?>

    Another way to consider it is to make your “yes” clauses dependent on inline php code:

    <ul>
    <li class="<?php
    if (is_page('whatever')) echo "yes"; else echo "no";
    ?>"> whatever goes in the li </li>
    </ul>

    See? The PHP is inside the class, and it creates the “yes” or “no” as needed.

    Hopefully this enough to get you going. Once you understand that PHP code must be in <?php ?> tags, then it’s fairly easy to work with. Just leave the large blocks of non-php code outside those tags.

    Thread Starter Alex Cragg

    (@epicalex)

    ok, sorted thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘is_page() with a list, not a function’ is closed to new replies.