I have 1 blog block in the home page where i am displaying the title and body of the body of the blog up to 2 lines.After that I want to add read more link which redirect to the blog content type.I am using views there in the preview it is read more link is showing correctly. but not displaying in the content page. I used this code below in node.content type.tpl.php to display the read more link. But the read more link is not adding to the blog . but to some other content in that page. Please suggest how to do this?

<div class="content"<?php print $content_attributes; ?>> <?php hide($content['links']); hide($content['links']['#links']['node-readmore']); print render($content); if($teaser) { print l(t('Read more'), 'node/' . $nid, array('attributes' => array('class' => t('node-readmore-link')))); }?></div> <?php print render($content['links']); ?>

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.


Not Getting your question exactly.But if you want to add read more link in the block then why are you written the code into node tpl file.No need to writing code into tpl file.If views preview shows the link then it will definitely render on the page.Make sure you checked it as admin. If you check it as anonymous user then it may be an issue of menu permission.

  • actually it is not directly rendering from views page. from Views page it is rendered to template.php and from the template.php to the content page – shailja ranjan Apr 11 '17 at 13:15

According to the my understanding of your question you want to display the some characters of the body on the node content page then GO to the content type body field in "manage display" Select the trimmed option with limit of characters

See the screenshot:

enter image description here

  • actually the body is getting trimmed there is no issue in that. but I want to add read more link with the trimmed body that is not displaying – shailja ranjan Apr 11 '17 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.