Jump to content

[SOLVED] Blogger Reverse Post Order


robindean

Recommended Posts

There's already a huge javascript out that does this but it's really robust. I've already gotten it working but PHP is such a hot mistress that I simply have to delve in.

 

What I want to do is rearrange content so that it lists chronologically (earliest date on top, latest date on bottom).

 

So far, my template is as follows (note that this is used to post upcoming concerts, so past shows are rendered "hidden") ...

 

Any takers?

 

Code:

 

<?php

$date = date("Ymd");

<blogger>if ($date <= <blogdateheader><$blogdateheaderdate$></blogdateheader>)
{
print ('<span class="blue"><b>');
print date("n.j.Y (l)",strtotime('<blogdateheader><$blogdateheaderdate$></blogdateheader>'));
print (' - <$blogitemtitle$></b></span><br><$blogitembody$><br><br>');
}
</blogger>

?>

 

... There are going to be many of these. How do I get them to print chronologically?

Link to comment
Share on other sites

It does work.

 

The blogger tags are replaced by content.

 

Everything between <blogger> and </blogger> runs as a loop, depending on how many posts I publish.

 

Hence, where you see "blogdateheaderdate" ... that's the yyyymmdd tag for the date it was published (if current date is less than or = blogger publish date, print yada).

 

I simply adjust the date on my publishing for upcoming shows and voila.

 

Any ideas for reversing the post order?

Link to comment
Share on other sites

Thanks and will do, although I might not be savvy enough right off the bat.

 

The javascript that is out there creates a "container" for everything before rearranging it. I want to recreate this for php.

 

I'm trying to find a way to assign an id, such as $idname<bloggerdate> (to produce something like $idname20070315), and then have the id names be reordered before printing to screen chronologically.

 

How might I do this?

Link to comment
Share on other sites

if you have a value say $x = "idname20070315"; you can use $$x = "some value"; which will make $idname2070315 = "some value";

 

I would put them into an array instead and do a sort on the array. You can sort in reverse which is what you want just make sure the key is 20070315 or the value to do this.

 

see php.net sort for more information.

 

Link to comment
Share on other sites

hmmm ... it's going to be more complicated, I think.

 

<blogger>everything in between</blogger> == one variable.

 

I need to encompass EVERYTHING between <blogger> and </blogger> into a variable, then rearrange all of the variables via an array, then print the rearranged version of the content.

Link to comment
Share on other sites

Let's say I have 3 posts which I've published via blogger. That would convert this ...

 

<?php

$date = date("Ymd");

<blogger>if ($date <= <blogdateheader><$blogdateheaderdate$></blogdateheader>)
{
print ('<span class="blue"><b>');
print date("n.j.Y (l)",strtotime('<blogdateheader><$blogdateheaderdate$></blogdateheader>'));
print (' - <$blogitemtitle$></b></span><br><$blogitembody$><br><br>');
}
</blogger>

?>

 

into this ...

 

<?php

$date = date("Ymd");

if ($date <= 20070318)
{
print ('<span class="blue"><b>');
print date("n.j.Y (l)",strtotime('20070318'));
print (' - Live Performance @ Poopy Joe/'s Poop Shack</b></span><br>Be there or smell better</span><br><br>we/'re gonna have a poopy time<br><br>');
}
if ($date <= 20070316)
{
print ('<span class="blue"><b>');
print date("n.j.Y (l)",strtotime('20070316'));
print (' - Live Performance @ Bumb Spankers Hoo-Ha</b></span><br>Featuring Linda Lovelace</span><br><br>we/'re gonna have a bang<br><br>');
}
if ($date <= 20070313)
{
print ('<span class="blue"><b>');
print date("n.j.Y (l)",strtotime('20070313'));
print (' - Live Performance @ Yo Yo Ma/'s Mama/'s House</b></span><br>Featuring Yo Yo Ma on Cello and Skin Flute</span><br><br>Mama be bakin/'<br><br>');
}

?>

 

Now, assuming that todays date is March 15th, only the first two posts will be displayed (be reminded, I'm posting with future dates because these are upcoming music performances).

 

The reason, if not obvious, is because the third $dates is NOT greater than or equal to the date of the post.

 

So, this much I have working and working nicely. The problem is that I don't want for viewers to see the last show on my schedule first. I want them to see the NEXT upcoming show FIRST.

 

I need to rewrap everything which falls below/between $date = date("Ymd"); and ?> in chronological order by $date.

 

My calculations on how to even start are foggy. Any help will just make me that much smarter.

Link to comment
Share on other sites

I got it working. Here's a scaled down rendering of what I came up with. Note that it makes use of layout elements the one likely wouldn't want on their site as opposed to my own ...

 

<?php
$date = date("Ymd");
<blogger>$post<blogdateheader><$blogdateheaderdate$></blogdateheader> = "<blogdateheader><$blogdateheaderdate$></blogdateheader>";
$date<blogdateheader><$blogdateheaderdate$></blogdateheader> = date("n.j.Y (l)",strtotime('<blogdateheader><$blogdateheaderdate$></blogdateheader>'));
$body<blogdateheader><$blogdateheaderdate$></blogdateheader> = " - <$blogitemtitle$></b></span><br><span class=\"purple\"><$blogitembody$><br><br>";
$build<blogdateheader><$blogdateheaderdate$></blogdateheader> = $post<blogdateheader><$blogdateheaderdate$></blogdateheader>.$date<blogdateheader><$blogdateheaderdate$></blogdateheader>.$body<blogdateheader><$blogdateheaderdate$></blogdateheader>;
</blogger>$array = array(<blogger>$build<blogdateheader><$blogdateheaderdate$></blogdateheader>, </blogger>null);
sort($array);
foreach ($array as $output)
{
print substr($output, ;
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.