• Hi there

    can someone give me an example of how to put code in a text widget for an if else statement

    i want it to say

    if its page 4400 then show form A

    else if its page 4401 then show form B

    etc

    forms are just standard forms

Viewing 6 replies - 1 through 6 (of 6 total)
  • Are these Posts or Pages? Where are the forms on the server?

    You can’t use php in any of the native WP widgets but you could edit the relevant template file (such as sidebar.php) and add the code.

    Thread Starter stargate03

    (@stargate03)

    Hi there

    the forms are currently just in the text widget

    how would i use php to place it in the sidebar, in order to determine if its a certain page then show a certain form

    Two basis options:

    1. Add the markup for both forms to your sidebar and use what’s called a conditional to control what form is shown and when.

    2. Duplicate your sidebar, add the forms to Text widgets on different sidebars and then use a conditional to control what sidebar to show

    Which would you prefer? You still didn’t confirm whether 4400 and 4401 are Posts or Pages…

    Thread Starter stargate03

    (@stargate03)

    They are pages

    if i use a conditional whats the code for that

    i guess its something like

    if ($postID = “4401”)

    <?php if( is_single('4400') ) :?>
    [ do foo ]
    <?php elseif( is_single('4401') ) :?>
    [ do bar ]
    <?php endif;?>

    http://codex.wordpress.org/Conditional_Tags#A_Single_Post_Page

    Thread Starter stargate03

    (@stargate03)

    Thanks for that works great except the

    is_single needed to be is_page

    many thanks

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Code in a widget’ is closed to new replies.