PDA

View Full Version : Immerse PHP Help


WaterPKMNMaster
June 21st, 2007, 05:37 PM
So I am using the new Immerse CMS, and you have to know PHP stuff to make some other stuff work. Problem is, I barely know anything about PHP - I'm a manual kind of guy. But anyways, see this URL:

http://www.pokebeach.com/immerse

The recent updates box is displaying all of the news stories under their own titles, but I want it to display stories created on the same day under the same title. For example, the first four Tuesdays' news stories should be under one Tuesday. I also want only the past 3 days of news to be displayed.

This is the PHP code for that box.

<?php
// Latest

$num_long = 5;

// get news pages
$pages = $immerse->get_full_children($folder, '*', 'created_date DESC');

$output = '';

foreach($pages as $page) {


// add the date and author
$output .= '<h2>'.date('l, F jS', $page['created_date']).'</h2><ul>';

$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.'</li></ul>';

}
echo $output;

?>

This is the basic skeleton of the box:

<h2>Date (in the format already present in the above coding)
<ul>
<li>Story Title</li>
<li>Story Title</li>
</ul>

Can anyone help me out?

Virtual Headache
June 21st, 2007, 05:55 PM
Well, I'm not sure which format the date is saved as.
Can you post an example?

While looking for all the entries in your data file, this will compare whether the date which was selected before is the same as the current one.

I can't guarantee this will work though, since I'm not sure about the format the date is saved in.

<?php
// Latest

$num_long = 5;

// get news pages
$pages = $immerse->get_full_children($folder, '*', 'created_date DESC');

$output = '';
$currentdate=0;
foreach($pages as $page) {

if ($page['created_date']!=$currentdate)
{
// add the date and author
$output .= '<h2>'.date('l, F jS', $page['created_date']).'</h2><ul>';

$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.'</li></ul>';
$currentdate=$page['created_date'];
}
else
{
$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.'</li></ul>';
$currentdate=$page['created_date'];
}
}
echo $output;

?>

WaterPKMNMaster
June 21st, 2007, 05:59 PM
Thank you for helping me! :)

I updated the coding with your code, but it is still spitting out the titles the same.

Virtual Headache
June 21st, 2007, 06:06 PM
I assume it's saved in Unix time format?
So the date has to be converted.
Try it now^^
<?php
// Latest

$num_long = 5;

// get news pages
$pages = $immerse->get_full_children($folder, '*', 'created_date DESC');

$output = '';
$currentdate=0;
foreach($pages as $page) {

if (date('l, F jS', $page['created_date'])!=$currentdate)
{
// add the date and author
$output .= '<h2>'.date('l, F jS', $page['created_date']).'</h2><ul>';

$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.'</li></ul>';
$currentdate=date('l, F jS', $page['created_date']);
}
else
{
$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.'</li></ul>';
$currentdate=date('l, F jS', $page['created_date']);
}
}
echo $output;

?>

WaterPKMNMaster
June 21st, 2007, 06:08 PM
Now it says:
Parse error: syntax error, unexpected T_IS_NOT_EQUAL in /home/.harmony/pokebeach/pokebeach.com/immerse/data/cache/icms/components/component.latest.php on line 13


I don't need to format the date - I know how to do that. I want it so that when the news stories are displayed, they are grouped by date, and only the past three days of news. :p

Virtual Headache
June 21st, 2007, 06:13 PM
Yeah, I now, but you need it for comparison.
I fixed the code, I used a ) too much. Try it again^^

WaterPKMNMaster
June 21st, 2007, 06:15 PM
Okay, now it is displaying all of the news story titles, but not the actual dates:

http://pokebeach.com/immerse/

(The fifth news story is manually in there - not generated).

Again, thank you for coming to help me with this! :)

Virtual Headache
June 21st, 2007, 06:22 PM
Ok, this will hopefully my last try^^
I really hope it will be working now^^

<?php
// Latest

$num_long = 5;

// get news pages
$pages = $immerse->get_full_children($folder, '*', 'created_date DESC');

$output = '';
$currentdate=date('l, F jS', $page['created_date']);
foreach($pages as $page) {

if (date('l, F jS', $page['created_date'])!=$currentdate)
{
// add the date and author
$output .= '<h2>'.date('l, F jS', $page['created_date']).'</h2><ul>';

$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.'</li></ul>';
$currentdate=date('l, F jS', $page['created_date']);
}
else
{
$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.'</li></ul>';
$currentdate=date('l, F jS', $page['created_date']);
}
}
echo $output;

?>

WaterPKMNMaster
June 21st, 2007, 06:27 PM
Now it says: Undefined variable: page

:p

Virtual Headache
June 21st, 2007, 06:58 PM
Ok, another try.
I already feel like a spammer for posting so many times xD
<?php
// Latest

$num_long = 5;

// get news pages
$pages = $immerse->get_full_children($folder, '*', 'created_date DESC');

$output = '';
$currentdate=0;
foreach($pages as $page) {

if (date('l, F jS', $page['created_date'])==$currentdate)
{
$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.'</li></ul>';
$currentdate=date('l, F jS', $page['created_date']);
}
else
{
// add the date and author
$output .= '<h2>'.date('l, F jS', $page['created_date']).'</h2><ul>';

$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.'</li></ul>';
$currentdate=date('l, F jS', $page['created_date']);
}
}
echo $output;

?>

WaterPKMNMaster
June 21st, 2007, 07:01 PM
Hey, at least we are making Webmaster's Discussion more active.

The same thing is happening as my post before last - the titles are showing, but not the dates they were created.

Virtual Headache
June 21st, 2007, 09:25 PM
Ok, finally :P
I tested it as well as I could (not fully since I don't have Immerse installed anywhere).

If this doesn't work, then I might give up, it's pretty hard to make something if you can't fully test it.

<?php

// Latest

$num_long = 5;

// get news pages
$pages = $immerse->get_full_children($folder, '*', 'created_date DESC');


$output = '';
$currentdate=date('l, F jS', 0);

foreach($pages as $page)
{
$comparedate=date('l, F jS', $page['created_date']);

if ($comparedate==$currentdate)
{
$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.'</li></ul>';
$currentdate=date('l, F jS', $page['created_date']);
}
else
{
// add the date and author
$output .= '<h2>'.date('l, F jS', $page['created_date']).'</h2><ul>';
$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.'</li></ul>';
$currentdate=date('l, F jS', $page['created_date']);
}
}

echo $output;

?>

WaterPKMNMaster
June 22nd, 2007, 02:15 AM
YAY! IT WORKED! I just had to fix the way the ul's and li's were in your code, but it WORKED! :D

Thank you! That was really nice of you to randomly come in here and help me. :) I appreciate it!

One last thing, since you obviously know your PHP: Can you make it so that only the past 3 days of news display (as in, if I posted something on Sunday, Monday, Wednesday, and Thursday, only Monday, Wednesday, and Thursday's stories show?). I changed that number in the coding on the top (the num long or whatever it's called) to 3, but it's still showing everything - that would be bad if I post something everyday. :p

Again, thank you so much! :D :D

EDIT: Oh, one more thing, if it's not too much trouble... Is it possible to put the time the story was posted next to the story? As in, next to "Four New Shining Darkness Scans," it displays "Four New Shining Darkness Scans (01:57 AM)."

Virtual Headache
June 26th, 2007, 10:10 AM
OK, I changed it.
I hope it will work. since I didn't test it.

<?php

// Latest

$num_long = 5;

// get news pages
$pages = $immerse->get_full_children($folder, '*', 'created_date DESC');


$output = '';
$currentdate=date('l, F jS', 0);
$maximum_days_displayed=0;

foreach($pages as $page)
{
$comparedate=date('l, F jS', $page['created_date']);
while ($maximum_days_displayed<3)
{
if ($comparedate==$currentdate)
{
$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.' ('.date("h:i A", $page['created_date']).'</li></ul>';
$currentdate=date('l, F jS', $page['created_date']);
}
else
{
// add the date and author
$output .= '<h2>'.date('l, F jS', $page['created_date']).'</h2><ul>';
$title = isset($page['longtitle']) ? $page['longtitle'] : $page['title'];
$output .= '<li>'.$title.'</li></ul>';
$currentdate=date('l, F jS', $page['created_date']);
$maximum_days_displayed++;
}
}
}

echo $output;

?>