Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$60
Change the class of a blogroll link if older than 30 days
I have this code:
<ul><?php wp_list_bookmarks('title_li=&categorize=0&category=89&orderby=name'); ?></ul>It outputs the bookmarks/blogroll links from the link category 89, orders the list alphabetically and removes the heading. Easy :)
It contains many bookmarks but I'd like to change the CSS class of links that are older than 30 days (or any other number of days). The reason I want to do this is I want to automate the process of adding a 'new' badge next to the most recent links.
Here's some examples so you can have a better idea of what I'm trying to do:
If bookmark is added today = CSS class of 'new'
If bookmark was added last year = CSS class of 'old'
If bookmark was added 29 days ago = CSS class of 'new'
If bookmark was added 30 days ago = CSS class of 'new'
If bookmark was added 31 days ago = CSS class of 'old'
So, is it possible?
Thanks a lot!
*UPDATE: Thanks a lot guys! I just tried both solutions.
For some reason Japh's solution made my H2 headings (which I'm adding manually) turn into links and also did something weird with some of my jQuery (collapsorz plugin acting weird)... I'm not sure what happened, but it does looks like a very promising solution since it doesn't need editing of a core file. Is there maybe a typo in the code provided that may cause the headings to turn into links?
As for Utkarsh's solution, well, even though it means editing a core file, it worked great! Actually I don't mind editing a core file. Of course I'd prefer not to, but it's still a viable solution. I should also mention that Utkarsh's solution uses the Link Updated plugin: http://wordpress.org/extend/plugins/link-updated/
I think both your solutions are pretty good nonetheless. Thanks a lot! :)
UPDATE #2: I just upped the prize amount a bit and will award both of you half of the amount as soon as my Paypal payment shows up here.
Thanks a lot for the help, Japh and Utkarsh! :)
This question has been answered.
Jon Phillips | 01/08/10 at 12:11am
Edit
(2) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
01/08/10
3:17amUtkarsh Kukreti says:You will have to edit the file wp-includes/bookmark-template.php
Around line 99
from
to$output .= '<a href="' . $the_link . '"' . $rel . $title . $target . '>';
$output .= '<a href="' . $the_link . '"' . $rel . $title . $target . custom_link_class($bookmark) . '>';
Then add the following code to theme functions.php
function custom_link_class($bookmark)
{
$days = 30;
$time = $days * 86400;
if(strtotime($bookmark->link_updated) + $time > time())
{
return ' class="new"';
}
return '';
}
Edit: looks like Japh missed a
in that</a>
$str .= '<li><a' . ($datediff <= $days_old ? ' class="new"' : '') . ' href="' . $b->link_url . '" title="' . $b->link_description . '">' . $b->link_name . '</a></li>';
Excellent solution anyways!Previous versions of this answer: 01/08/10 at 2:47am
-

Last edited:
01/08/10
3:17amJaph says:Place the following in your functions.php file for the active theme:
function edit_link_update($link_ID) {
global $wpdb;
$sql = "update wp_links set link_updated = NOW() where link_id = " . $link_ID . ";";
$wpdb->query($sql);
}
add_action('edit_link', 'edit_link_update');
function get_bookmarks_fresh($args, $days_old = 30) {
$bookmarks = get_bookmarks($args);
$str = '';
foreach ($bookmarks as $b) {
$datediff = ((((date('U') - date('U', strtotime($b->link_updated))) / 60) / 60) / 24);
$str .= '<li><a' . ($datediff <= $days_old ? ' class="new"' : '') . ' href="' . $b->link_url . '" title="' . $b->link_description . '">' . $b->link_name . '</a></li>';
}
echo $str;
}
Then where you would normally put "wp_list_bookmarks", put "get_bookmarks_fresh" instead, like:
get_bookmarks_fresh('orderby=name');
I have found that "link_updated" doesn't seem to be set correctly in a default WP install, which is why the 'edit_link_update' function is there.
Also, I should mention that editing core file like "/wp-includes/bookmark-template.php" is not such a great plan, as an upgrade may destroy your changes.
Edit: Fixed the typo causing link troubles! Sorry about that :)Previous versions of this answer: 01/08/10 at 2:17am | 01/08/10 at 3:07am | 01/08/10 at 3:08am
This question has expired.
Current status of this question: Completed
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
