PDA

View Full Version : Conditional statement for calendar inclusion


gunn4r
07-27-2009, 06:18 PM
I'd like to use conditional statements to include the calendar on my webpage, however, I am pretty noob at php, if anyone can help me out that'd be sweet.

I would like the regular calendar to appear in the side bar on just the home page, and would like to only include the css code and mouse over code for that page as well (and not have it on other pages), and so would like to use an if statement to make that happen... however I dont know what function to use to run the script.

I've tried require, echo, and include to no avail. Can anyone help? I just need to know what to put where the ????'s are: ... or am is what I have there totally not right? hah.


<?php if (is_home()) ????? '<?php $OL=1;require("cal/calendar.php"); ?>' ?>

gunn4r
07-27-2009, 07:04 PM
Okay got conditionals to work using:

<?php if (is_home()) $OL=1; require("cal/calendar.php"); ?>

Now im tryen to figure out how to do some kind of else if to make it show up on my calendar page as well.

ve9gra
07-27-2009, 07:04 PM
No, you're already in the PHP code at that time, you don't want to echo the strings out to the file, you just want to set them.
<?php
if (is_home()) {
$OL=1; require("cal/calendar.php");
}
?>

ve9gra
07-27-2009, 07:05 PM
Doing it your way, you actually have half of it in the loop, and the other half out. Make sure to use what I posted. The curly brackets are important.

gunn4r
07-27-2009, 07:19 PM
Sweet. I'm almost there.

Right now what I'm using (and it's working) is:


<?php
if (is_page('calendar')) {
$CSS=1; require("cal/calendar.php");
}
?>
<?php
if (is_home()) {
$CSS=1; require("cal/calendar.php");
}
?>

</head>

<body>

<?php
if (is_page('calendar')) {
$OL=1; require("cal/calendar.php");
}
?>
<?php
if (is_home()) {
$OL=1; require("cal/calendar.php");
}
?>
However i'd like to just use one if statement for each. but when I do


<?php
if (is_page('home','calendar')) {
$CSS=1; require("cal/calendar.php");
}
?>


</head>

<body>

<?php
if (is_page('home','calendar')) {
$OL=1; require("cal/calendar.php");
}
?>

It doesn't work. I'm sure its because the home page isn't actually a "page" called home. Is there an ID for the home page, or some way that i can make this work in one statement?

ve9gra
07-28-2009, 11:00 AM
I'm going to take a wild guess and say that
<?php
if (is_page('calendar') || is_home()) {
$OL=1; require("cal/calendar.php");
}
?>should work.

gunn4r
07-28-2009, 02:09 PM
Worked like a charm, thanks! :)