Sitemap for dynamic PHP website ... the "lastmod" field is needed? - php

I've a really small website, so I usually update the sitemap by hand!
In each "url" element there are the fields: loc, lastmod, changefreq and priority.
The "lastmod" field is setup to the date in witch I update the content of the related PHP page or the content that is loaded dynamically in the related PHP page!
I've tried to use http://www.xml-sitemaps.com/ to verify if all it was right, and I've noticed that in the generated sitemap there isn't the "lastmod" field!
In the Google wiki, about how to write a sitemap, there's written that is a good practice to setup the "lastmod" field even for dynamic pages; so, my question is ...
Is the "lastmod" field needed or not?
Thanks in advace!

$lastmod = date('Y-m-dTH:i:s+00:00');
for more info,
http://www.w3.org/TR/NOTE-datetime

You can use php date function to create last mod
How Last mode value is created
<sitemap>
<loc><?php echo url('/') ?>/sitemap/uk/lse/list</loc>
<lastmod><?php echo date('c', time()); ?></lastmod>
</sitemap>

The standard says that it's optionnal : http://www.sitemaps.org/protocol.php#locdef :
<lastmod> optional
The date of last modification of the
file. This date should be in W3C
Datetime format. This format allows
you to omit the time portion, if
desired, and use YYYY-MM-DD.
Still, it might be usefull to let search engines / spiders know when your content was updated for the last time.
The How do I compute lastmod date? entry of the FAQ also gives an interesting reason, that explains why you should include the lastmod date if you can (quoting) :
Using even an approximate date or
timestamp can help crawlers avoid
crawling URLs that have not changed.
This will reduce the bandwidth and CPU
requirements for your web servers.

It's not mandatory but it's good to have it in order to let Google (and other engines) know when content updates happen on your site.

Related

Change RSS feed, but only new items

I'm fairly new to PHP, and I'm trying to write a script that solves the following
I have an RSS feed that gets saved to my server every 10 minutes (copied from elsewhere).
There is a problem with the timestamps (pubDate tag) on the RSS feed, they always have the correct date but 00:00:00 GMT as the timestamp (I have no control over this).
Therefor, when I use an autotweeting program to tweet updates from the feed (it checks it every hour or so), it won't - It only tweets the first update of each day as a result.
Therefor, what I'm trying to do to fix it to some degree is to check if the feed has changed, and if it has, change the saved pubDate to the current server time on only the new items.
I'm also kind of confused as to how I can have it check for changes - If I have a corrected version (with fairly accurate timestamps) saved to my server, it will ALWAYS think there are changes, because the timestamps will always be 00:00:00. I'm thinking, check both feeds for items including the full strings such as <guid isPermaLink="true">http://services.runescape.com/m=adventurers-log/a=161/display_player_profile.ws?searchName=A13d&id=-463827091</guid> - Since the id= at the end stays constant, it would only change the <pubDate> of items found to be new.
http://services.runescape.com/m=adventurers-log/a=161/rssfeed?searchName=A13d Here is a feed as an example. If anyone could get me started or point me to some kind of tutorial that might help, I'd really appreciate it. This is over my head, but something I need to learn how to do.
Maybe there is something wrong with your code parsing the timestamp, date format perhaps?
I believe the method of doing full string comparisons(<title> & <description>) between items with the same <guid> is your best bet. Here is some reading about RSS duplicate detection if you are interested.

Google Calendar Feed

I am trying to add a Google calendar to a website I'm making that the client will be able to update themselves. I found this: http://mikeclaffey.com/google-calendar-into-html/ which has been quite helpful, but I am a bit stuck.
The website I am building is using PHP template and the page contents is contained within the $content variable. Here is the link I'm working on: http://victoriasawyer.com/AmosTheTransparent.
The calendar feed is the top one of the two lists of Tour Dates. I would like the top one to look similar to the bottom one. The same would be ideal but not necessary.
The biggest issue I'm having is with the start date and time. In the title of the event I would like just the date to show (preferably like 10/03/14) not the time. I have figured out how to display just the time separately without issue. Is there some way to change the date format?
The other issue I'm having is the order that the events are appearing. I would like the events to show with the soonest one first in the list and the furthest one last in the list. I added the additional parameters as instructed in the tutorial (orderby=starttime and sortorder=ascending) but they do not display correctly.
The url I am using is: https://www.google.com/calendar/feeds/qmfadhgtq2kmabsi3dlb456v98%40group.calendar.google.com/public/full?orderby=starttime&sortorder=ascending&futureevents=true&alt=json. Is there something I can adjust or add to fix the order?
Any help will be much appreciated (even if you can recommend an alternative. It just needs to be customizable, and so far this seems to be the best option I have found).
You can use PHP's DateTime class like this:
$date = new DateTime('Sun Nov 16 2014 00:30:00 GMT+0000');
echo $date->format('Y-m-d');
You can then use the predefined formats in PHP which are listed here to format it into whatever style you like.
echo $date->format('d/m');
echo $date->format('d/m/Y');

lastBuildDate in dynamically generated RSS

RSS feed being generated on demand.
As far as I can see, for I have 2 options for lastBuildDate - current time or pubDate.
Which one would you choose and why?
According to the RSS 2.0 spec, lastBuildDate is the last time the content of the channel changed. (I'm not entirely satisfied with this definition because what if the feed's meta data changes? I think the common convention is to update lastBuildDate in that case, too.)
The channel-wide pubDate is supposed to be used for the original publication date of the items in the feed. It is never a good value to use for lastBuildDate because the pubDate is to stay unchanged even if the item gets updated.
Using the current time is the easy way out, but it's not perfect (because clients may start unnecessary operations due to the changed lastBuildDate)
The best way would be to actually know / find out when the feed's content last changed, and output that.
Related question
The item having the newest PubDate should become the lastBuildTime.
[EDIT]: If there is a separate PubDate you are using too for whole feed, then lastBuildTime should be current time because you are building it at current time on-demand :).
[EDIT]: 2:: As lastBuildTime is optional and you're anyways including PubDate for whole feed, why not remove it from your feed output?

wordpress sort search results by date

Is there any special parameter that i can pass to search url to sort it by date .
And is there any parameter to increase the number of search results returned ?
Thanks
WordPress search is already sorted by date, most recent first. If that's not what you're looking for, you're out of luck without using plugins and/or editing source code. So no, (taking a guess here) you can't pass URL parameters to a search on a 3rd party WordPress site to change the info you get back.
This quote from Joost de Valk, one of the leading WordPress gurus out there, from his site yoast.com
WordPress default search kinda sucks. It sorts the results by date, newest first, and interface wise it doesn't have any of the cool things we're used to when we search in for instance Google.
That article is mainly on how to improve the search functionality of your own site.
I've made some modifications on the Search Unleashed plugin, it's the best one I've found and is pretty customizable
I believe this plugin will allow you to sort by date: http://wordpress.org/extend/plugins/search/
Hope it helps!

NetBeans Code Templates ${date}?

I have this code template in Eclipse
#since ${date}
when entered i get something like this :
#since 4.8.2009
But when i add the same template (#since ${date}) to NetBeans
it outputs
#since date
Can someone help ?
No answer yet ? Is this not possible in Netbeans ???
Something like the following example should doing the job :
${date?date?string("yyyy")}.${date?date?string("MM")}.${date?date?string("dd")}
yyyy => year on 4 elements (ex: 2012)
MM => Month on 2 elements (ex: march -> 03)
dd => Day of the month on 2 elements (ex: 23)
. => separator you want to separate each fields (ex: - or / or . or smth else)
You should have to check about available format somewhere in the netbeans help (sorry I don't find out informations about this for now).
I see that's a very old post, but if it may usefull for someone ...
regards.
ollie314
Not wanting to raise the dead with this post, but I thought it worth mentioning so I signed up to SO specifically to clarify, since Ollie314 saved me a lot of time.
The format ollie314 used is correct (for version 7.1+ at least) BUT just to be clear, if it's not displaying correctly it may be due to your system locale settings, if outside of USA. Be sure to include <#setting locale="en_AU"> (replace en_AU with your locale id) in the template you are editing, prior to the date?date?string cast declaration, or it will not work. If you place it in the user settings it won't cast the date string in the template and you will generate errors in your template output.
The documentation from Netbeans isn't particularly clear on that. Still, best IDE ever :)
Inserting ${date?date?string("yyyy")} within your template will do the trick (if you want year only)
Note: With NetBeans 6.5/6.7, if you do not find that template, you could create it.
See this tutorial.
I'm pretty sure this is not possible in Netbeans, or at least not worth the amount of trouble. It's possible that you could author your own Netbeans module, add a code template to the module (in which you might be able to put the ${date} as an extra variable, I'm not sure), and then add the module to Netbeans. But you could also just type the date in, which, unless you type it several thousand times per day, would probably take less time.
Your snippet looks like freemarker code. This is used in Netbeans for file templates (Tools -> Templates). If you put ${date} in a file template it will get transformed when the file is created to the current date. If you're trying to use it as a code template I don't know how that works.
Even simpler, use ${date?date?string.yyyy}

Categories