last day (20 days later) » 

1:35 PM
1
A: D7: Conditionally format node fields from nodes less than 14 days old

Елин Й.You can do that using a preprocessor function for the view you created. You need to preprocess the view and check the creation date of nodes for each row and give them a relating class. Let's assume that your view's machine name is latest_news, your diplay format is HTML lists, and your theme n...

 
Thanks, this looks like the correct way to go. However, the code (adapted for my theme's name and view name) isn't working. <code>function ubercompany_preprocess_views_view_list(&$variables) {
$view = $variables['view'];
if ($view->name == 'recent_news_widget') {
dpm($view);
// logic
}
}</code> isn't rendering the variable data? I presume it renders to the message box, but it isn't?
 
You need to clear cache, at least the theme registry. Yes, it should render it to the messages region.
Oh, and the preprocess function was an example for a view that has a display type of HTML List. If your display type is different, then you need to use its preprocess function. I'll update my answer and list the preprocess functions for each display type.
 
I have set Devel's Rebuild the theme registry on every page load (and routinely use drush cc all) and I presume the view is an HTML List type, i.e., $handler->display->display_options['style_plugin'] = 'list'; but to no avail.
 
To debug i'd remove the first if condition and try to dpm the view without checking the view name. However if you have too many views on the same page, you could get memory errors.
 
Tried that, didn't show, i.e., inserted print($view); just after the variable is set, which suggests that ubercompany_preprocess_views_view_list(&$variables)isn't being triggered?
 
 
1 hour later…
2:40 PM
sorry I had to leave. I won't be able to get online in the following 4-5 hours.
are you sure that the view is loaded on the page you are trying to call the preprocess function?
 
3:28 PM
try that to be sure if the function is triggered at all:
function ubercompany_preprocess_views_view_list(&$variables) {
dpm ('test');
}
 
 
2 hours later…
5:43 PM
No worries, I had a tree come down. Thanks for all your help so far; I'll be trying this shortly.
 
 
2 hours later…
7:29 PM
Well, crap! Something's up with my template.php. I switched to bartik in /modules added the line (updating the function name's 'prefix') and I see the output now. Which means the template.php isn't working, or… ?
Double-crap! This seems to be a problem with Gensis — drupal.org/node/1351056
Added the preprocessor theme to the base theme, and I see the output now
Alright, alright; we're cookin' now. My php is weak BUT I see
result (Array, 5 elements)
0 (Object) stdClass
node_changed (String, 10 characters ) 1371174569
node_title (String, 26 characters ) Less than 24 day old story
nid (String, 3 characters ) 457
node_created_day (String, 8 characters ) 20130613
I'm guessing that I will do some simple timestamp comparison, if the date is less than the value represented by 14 days, then add the class.
 
8:08 PM
good to hear that you have found the reason why it didn't work. It's the best way to go with timestamp comparison and adding a class if it's less than 14 days.
 
 
1 hour later…
9:21 PM
Cool, can you give me a rough idea of what that looks like? Much thanks!
 

  last day (20 days later) »