Skip to main content
added 236 characters in body
Source Link
Kevin
  • 28k
  • 12
  • 95
  • 196

All you have to do is add a field to the view output that is the node link, and give it the label of "Read more". You don't have to add anything to a template file for this unless you are using a view mode and telling Views to output a rendered entity.

If you are using a view mode, you don't need to add a field to the content type anyway. You can just edit the view mode template (node--node_type--view_mode.tpl.php if I am not mistaken) and output the node path as:

<?php print l('Read More', $node->nid); ?>

Note that since you are doing view mode templates, there is no reason to check for if ($teaser) - because you know you are working within a designated view mode template. I would advise creating a view mode like "Sidebar Item" so you know exactly what it is for. In this example, the template would be node--node_type--sidebar_item.tpl.php where node_type is page, article... whatever the node type is.

The code in your question is actually over complicating it in my opinion, and you can rectify this in just a couple of minutes by simplifying it.

All you have to do is add a field to the view output that is the node link, and give it the label of "Read more". You don't have to add anything to a template file for this unless you are using a view mode and telling Views to output a rendered entity.

If you are using a view mode, you don't need to add a field to the content type anyway. You can just edit the view mode template (node--node_type--view_mode.tpl.php if I am not mistaken) and output the node path as:

<?php print l('Read More', $node->nid); ?>

Note that since you are doing view mode templates, there is no reason to check for if ($teaser) - because you know you are working within a designated view mode template.

The code in your question is actually over complicating it in my opinion, and you can rectify this in just a couple of minutes by simplifying it.

All you have to do is add a field to the view output that is the node link, and give it the label of "Read more". You don't have to add anything to a template file for this unless you are using a view mode and telling Views to output a rendered entity.

If you are using a view mode, you don't need to add a field to the content type anyway. You can just edit the view mode template (node--node_type--view_mode.tpl.php if I am not mistaken) and output the node path as:

<?php print l('Read More', $node->nid); ?>

Note that since you are doing view mode templates, there is no reason to check for if ($teaser) - because you know you are working within a designated view mode template. I would advise creating a view mode like "Sidebar Item" so you know exactly what it is for. In this example, the template would be node--node_type--sidebar_item.tpl.php where node_type is page, article... whatever the node type is.

The code in your question is actually over complicating it in my opinion, and you can rectify this in just a couple of minutes by simplifying it.

Source Link
Kevin
  • 28k
  • 12
  • 95
  • 196

All you have to do is add a field to the view output that is the node link, and give it the label of "Read more". You don't have to add anything to a template file for this unless you are using a view mode and telling Views to output a rendered entity.

If you are using a view mode, you don't need to add a field to the content type anyway. You can just edit the view mode template (node--node_type--view_mode.tpl.php if I am not mistaken) and output the node path as:

<?php print l('Read More', $node->nid); ?>

Note that since you are doing view mode templates, there is no reason to check for if ($teaser) - because you know you are working within a designated view mode template.

The code in your question is actually over complicating it in my opinion, and you can rectify this in just a couple of minutes by simplifying it.