robindean Posted March 15, 2007 Share Posted March 15, 2007 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 https://forums.phpfreaks.com/topic/42806-solved-blogger-reverse-post-order/ Share on other sites More sharing options...
btherl Posted March 15, 2007 Share Posted March 15, 2007 Does your current code work? Edit: The reason I ask is that it doesn't look like valid php to me Link to comment https://forums.phpfreaks.com/topic/42806-solved-blogger-reverse-post-order/#findComment-207793 Share on other sites More sharing options...
robindean Posted March 15, 2007 Author Share Posted March 15, 2007 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 https://forums.phpfreaks.com/topic/42806-solved-blogger-reverse-post-order/#findComment-207801 Share on other sites More sharing options...
robindean Posted March 15, 2007 Author Share Posted March 15, 2007 bump Link to comment https://forums.phpfreaks.com/topic/42806-solved-blogger-reverse-post-order/#findComment-208152 Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 php.net look at date, time, mktime, strtotime functions. Probably your best bet also look at the user contributions they post good date verification/checking information. Link to comment https://forums.phpfreaks.com/topic/42806-solved-blogger-reverse-post-order/#findComment-208153 Share on other sites More sharing options...
robindean Posted March 15, 2007 Author Share Posted March 15, 2007 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 https://forums.phpfreaks.com/topic/42806-solved-blogger-reverse-post-order/#findComment-208182 Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 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 https://forums.phpfreaks.com/topic/42806-solved-blogger-reverse-post-order/#findComment-208183 Share on other sites More sharing options...
robindean Posted March 15, 2007 Author Share Posted March 15, 2007 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 https://forums.phpfreaks.com/topic/42806-solved-blogger-reverse-post-order/#findComment-208271 Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 Can you post an example of the raw data, if so I can take a look at it more thoroughly for you. Link to comment https://forums.phpfreaks.com/topic/42806-solved-blogger-reverse-post-order/#findComment-208272 Share on other sites More sharing options...
robindean Posted March 15, 2007 Author Share Posted March 15, 2007 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 https://forums.phpfreaks.com/topic/42806-solved-blogger-reverse-post-order/#findComment-208375 Share on other sites More sharing options...
robindean Posted March 16, 2007 Author Share Posted March 16, 2007 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 https://forums.phpfreaks.com/topic/42806-solved-blogger-reverse-post-order/#findComment-208667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.