I created a view sorted accorded to the Node:Sticky criterion.

However, in the output, I don't find any way to distinguish sticky nodes from non-sticky ones. Is there a way to tag sticky nodes with, say, a class='sticky' attribute?

Comments

ablivio’s picture

Status: Active » Closed (fixed)

The answer was quite simple: check the $node->sticky attribute in node.tpl.php, then add the relevant tagging in the HTML output accordingly.

Medya-1’s picture

i am trying to do the same would you please help me i am kind of noob in this

jfall’s picture

Here are some more details for Medya...

In your theme, look for node.tpl.php, near the top you should see some theming code like:

<div class="node 
   <?php  print ' ' . $node_type;
          if ($sticky)    { print ' sticky'; } 
          if (!$status)   { print ' node-unpublished'; } ?>" >

This is printing out the div tag, which should look like:

<div class="node sticky">

for sticky nodes. Use View... Source in your browser to see what the node div looks like.

Now you need to add some CSS to style the div, for example

div.sticky {
  border: solid 1px #ddd;
}

to put a light grey border around the node.

This is a good example of how theming works in general - Drual sets some variables (e.g., $sticky), or you set them yourself in template.php; you use these variables to format your HTML using one of the template (*.tpl.php) files; then you style the html with css.

hope that helps - good luck.

Medya-1’s picture

jfall thanks for your reply...I have already tried to do that. I am using views for frontpage..and if I select a story as sticky it is listed on the top but no class is assigned so the class is same a others :(

Medya-1’s picture

i think it does not print the div sticky tag for table view i have changed it to teaser list and it prints out the sticky tag..but i need it for table view

jfall’s picture

i need it for table view

That would have been useful information ;-)
So, you want an id added to rows in the table that contain a sticky node?

You probably need to override the theme_views_view_table function in your template.php file - but maybe I'm missing something (I did have a look, and as far as I can tell, Views does not look for the stick attribute when building the table data).

Perhaps you might try opening a new support issue for your specific issue (theme sticky nodes in table layout), as this thread is slightly different, and is a closed issue, so won't get much traffic.

good luck. You can contact me through my contact form if you want help with this.

marashi’s picture

I had the same problem and I fixed it as follows:

1- create a page for your view ... here is a page for 'block display' of a 'News' view.
views-view-fields--News--block-1.tpl.php

2- put it in this folder:
sites/all/themes/YOUR_THEME/views/

the content of this file is something like this

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="myview_news <?php if ($row->node_sticky) { print ' sticky'; } ?>">
  <tr>
    <td colspan="2" valign="top" class="myview_image"><?php print $fields['title']->content; ?></td>
  </tr>
  <tr>
    <td valign="top" class="myview_image"><?php print $fields['field_img_fid']->content; ?></td>
    <td valign="top" class="myview_desc"><?php print $fields['body']->content; ?></td>
  </tr>
</table>

by putting this snippet of code
<?php if ($row->node_sticky) { print ' sticky'; } ?>
it recognize whether this is a sticky node or not ... if so, it adds the sticky class to your code and then you can add some styles.

3-clear the cache
4- that's it.

errand’s picture

solution for D6.16 + views 6.x-2.10

hello everyone. this how i did for my table style view:

1. go to http://drupal_site/admin/build/translate/search
find: Sticky
replace to Sticky

2. in your view add field: node:sticky > /sticky

use CSS to set your .field_sticky span style

this how it looks http://scraft.ru

i hope my english no so bad )))

i loveD6.xx