Search code examples
drupaldrupal-7drupal-viewsdrupal-theming

Drupal: display views page instead of default node/%


Case is that im using views for displaying each of content-types.

eg. q=?news/12 for news by nid q=?product/13 for products by nid

Problem is when im creating (or editing) new content, it automatically displays (or refer) ?node/14 instead of ?product/14. Also menu link is created under node/14 link.

How could i set each view to referring content type?

Thanks in advance.


Solution

  • You can create a view (display mode : page) for each content type, which displays datas from your node (fields or whatever you need). To do so, add a contextual filter in your view, on content nid, give default value : content nid from URL. Then give to this view a URL like /news/%. So /news/12 hits this view and grabs data from news content type with id 12. Then you can manually modify menu link, or use Pathauto to specify /news/[node:nid] as a pattern for all your news nodes (I never tried all this stuff together but it should work).

    Other solution

    https://www.drupal.org/project/contemplate (seems deprecated...)

    Other solution

    Create a dedicated template file for your content type nodes : node--news.tpl.php, but no more views...

    Other solution

    Create a view displaying one particular node data (like I explained first, with a contextual filter), this view creates a block (display mode : block), you assign this block to a region (with block interface), and set this block to be displayed only for the news content type (last menu on the left on the block configuration page). Then with Display Suite you hide everything for this content type on the Full content display. So on each node page which refers to a news node, you have nothing in your page but your block (and the node title, which you can remove with Display Suite Extras I guess).

    Good luck with it