Forum Moderators: coopster

Message Too Old, No Replies

'endif' for 2 'if' functions but not wanting to end the first 'if'

         

Jim123

12:33 am on Mar 21, 2010 (gmt 0)

10+ Year Member



I'm a bit stuck. For my website I want a different sidebar on the homepage than on other pages.

I have ried the script below, but it's not working. The 'endif' kills the first 'if', but this one I need to continue for the script to work.

How can I use 'if' twice and 'endif' whereby 'endif' doesn't end the first 'if'?

Thanks
Jim


<div id="mainright">
<?php if ( is_home()) { ?>
<div id="sidebar" class="clearblock">

<ul>

<li id="sidebartabs">
<?php include (TEMPLATEPATH . "/sidebartabs.php"); ?>
</li>
<li>
<?php include (TEMPLATEPATH . '/sponsors.php'); ?>
</li>

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Right Sidebar') ) : ?>

<?php endif; ?>

</ul>
</div>
<?php } else { ?>
<div id="sidebar" class="clearblock">

<div class="feed">

<h2 class="sh">Subscribe here </h2>

<?php $feed = get_option('sdf_feed')?>

<form action="http://feedburner.google.com/fb/a/mailverify" method="post" target="popupwindow" onsubmit="window.open('http://feedburner.google.com/fb/a/mailverify?uri=<?php echo($feed); ?>', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true">
<input type="text" class="input" value="Sign Up here for email feed..." onfocus="if (this.value == 'Sign Up here for email feed...') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Sign Up here for email feed...';}" name="email"/>
<input type="hidden" value="<?php echo($feed); ?>" name="uri"/>
<input type="submit" class="sbutton" value="Submit" />
</form>

</div>

</div>
<?php } ?>

</div>

Matthew1980

3:14 pm on Mar 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there jim123,

From the example you have given, can you just use the elseif instead:-

if(this condition)
{
//Do something
}
elseif(another condition){
//do something else
}
elseif(similar condition){
//or do this
}

From my understanding of this type of if/else chain, it similar to using a switch().

Have a read of this:-

[uk2.php.net ]

See if it makes sense & if it will make any difference to what you are trying to do.

Hope I have understood you correctly ;-p

Cheers,
MRb

penders

9:30 pm on Mar 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



..., but it's not working. The 'endif' kills the first 'if'...


...and presumably you get some kind of parse error?

Jim123

3:05 am on Mar 22, 2010 (gmt 0)

10+ Year Member



And getting a parse error...

Jim123

3:07 am on Mar 22, 2010 (gmt 0)

10+ Year Member



Maybe to be more specific, this is want I want:

if page=homepage
show show sidebar for homepage
else
show a different sidebar.

I think the difficulty is that within the sidebar I also want to make use of the dynamic sidebar function.

Matthew1980

7:59 am on Mar 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there jim123,

If that does mean that you have the page set from the URL, then this would be Ok:-

if(isset($_GET['page']) && (strip_tags($_GET['page']) == "homepage"))
{

echo "this is the homepage sidebar";

//or include the file with the side bar in :)
include("path/to/nav/menu/sidebar_for_homepage.php");

}else{

echo "This is not the homepage, display something else";

//or, another menu...
include("path/to/nav/menu/sidebar_for_otherpages.php");

}

That is just simplyfiying the process, but the general idea is there.

Cheers,
MRb