Jump to content

Include content help


spacepoet
 Share

Recommended Posts

Hi:

 

I have this code that - when added to a page  - works fine:

<div class=\"<?php echo (time() <= strtotime('4/17/2011 2:00:00 AM')) ?  'myUpcoming' : 'myPassed'; ?>\">

<span class=\"myGameDate\">April 16:</span> <span class="myGameDateRed">Home</span> vs Baltimore

</div>

 

It's a schedule that will display one CSS style before the date, and another CSS style after the date. Works fine on the homepage.

 

I am trying to add it to an include navigation file, so I can add it to all the pages like this:

 

myNav.php

function spSchedule() {
$spSchedule =
"
<div class=\". echo time() ." <= strtotime("4/17/2011 2:00:00 AM") ? \"myUpcoming\" : \"myPassed\"; .\">

<span class=\"myGameDate\">April 16:</span> <span class=\"myGameDateRed\">Home</span> vs Baltimore

</div>          	

";
return $spSchedule;
}

 

myPage.php:

<?php
include('include/myNav.php');
?>

...

<?php echo spSchedule(); ?>

 

What it is doing is writing "myUpcoming" to the page, and that's it.

 

What am I missing on this, please?

Link to comment
Share on other sites

You can't use strings like that. Try this instead.

 

function spSchedule() {
  $x = (time() <= strtotime('4/17/2011 2:00:00 AM')) ?  'myUpcoming' : 'myPassed';
  $spSchedule =
"
<div class=\"". $x ."\">
<span class=\"myGameDate\">April 16:</span> <span class=\"myGameDateRed\">Home</span> vs Baltimore
</div>          	
";
  return $spSchedule;
}

Link to comment
Share on other sites

Excellent!

 

Thanks works perfectly.

 

One question:

 

How would I add more games?

 

Like this:

...
$x = (time() <= strtotime('4/17/2011 2:00:00 AM')) ?  'myUpcoming' : 'myPassed';
$x2 = (time() <= strtotime('5/17/2011 2:00:00 AM')) ?  'myUpcoming' : 'myPassed';


...

<div class=\"". $x ."\">
<span class=\"myGameDate\">April 16:</span> <span class=\"myGameDateRed\">Home</span> vs Baltimore Nighthawks
</div>               	
          	
<div class=\"clearAndPad\"></div>


<div class=\"". $x2 ."\">
<span class=\"myGameDate\">May 16:</span> <span class=\"myGameDateRed\">Home</span> vs San Diego
</div>               	
          	
<div class=\"clearAndPad\"></div>

...

 

 

Is that the best way?

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.