tags:

views:

38

answers:

1

I have a link within a block. At the moment it goes to a list of newsletter nodes:

<p><a href="<?php global $base_url; print $base_url;?>/news-events/newsletter">Read our latest newsletter</a></p>

What I would prefer is to have it go to the latest node of the content type 'newsletter', is this possible?

+1  A: 

There are two ways of doing this.

  1. The Views module is a great tool create stuff that requires SQL.
  2. Sometimes it's more practical for simple things like that to not use views, but write your own SQL instead. All you need is the node id of the latest node to get what you want. A query like this should get what you want:

    "SELECT nid FROM {node} WHERE type = 'newsletter' ORDER BY -nid LIMIT 1;"
    

    The link to the node would be node/nid where nid is the node id of the node.

googletorp
Thanks folks. I thought I couldn't use Views because the block was created elsewhere, but I forgot you could use 'print views_embed_view' within the appropriate tpl.php file.
james6848