English 中文(简体)
Drupal Add Static link to a view
原标题:

I have a Drupal view that lists a node called publication. At the top of the page I d like to have a link new publication instead of having it in the navigation block. Can somebody direct me on how to go about this? There seems to be several ways but I m having little luck.

最佳回答

I also struggled a bit in getting the exact meaning of your question.

I understand your question like this: "I have various pages of node listing generated by my view, I would like to have on top of each of these pages a link that allows me to create a new node of the type listed in the views. How do I do it?"

If I got your question right, a possible method is to insert the link in the template for your view. In fact the link to create a new node of that type will be a static URL of the type

http://example.com/node/add/mynodetype

so you can safely put in your template file something like:

<?php print(l( Create a new mynodetype article! ,  node/add/mynodetype )) ?>

This is substantially equivalent to what Henrik proposed (+1) by modifying the header of your view. What method you choose will probably depend on if you consider this link more of a core feature of your view or more of a theming element. If you add it to the view, you will have it in all your themes (=feature). If you put it in the template, you will only have it for the theme the template is used by (=theming element). Of course - even if it is a theme element - it makes more sense to include it to the view if you use a standard template file, so you will not have to crate an entire template file just for a link.

From your comment below it seems that you are not already using a template for your view, and therefore - unless you need it - you could go with Henrik s suggestion of adding the information in the header of the view. I however prepared screenshots to illustrate both methods:

Adding to the header:

You have to click on "header", then insert the code in the textfield and set the input filter to "PHP" (Otherwise your code will be escaped and displayed instead of being run).

Screenshot of views UI

Creating a template:

You have to click on "information: theme" and then you will have a list of possible template names. The one in bold is the one currently used. You then have then to copy the file with the bold name (from the views directory) to your theme directory, and rename it in one of the proposed ways. Then you can enter the file and edit it adding the PHP code you need.

As stated before: if you do not need a template for anything else, then creating a theme only for this is overshooting, IMO.

Screenshot of views UI

问题回答

You can also use the following module: https://www.drupal.org/project/views_linkarea.

As stated in its description,

"By making it a real link rather than just a blob of HTML in a header text area it gets all of the special handling and clean URL friendliness and base-path portability that any Drupal link gets."

Edit: Just realized that I probably misunderstood your question. You want a link on the top of every page, pointing to your view?


(Note: probably not what the OP wants, as it would put the link at the top of the view itself)

One of the easiest ways would be to put it in the header section of the view (under basic settings on your views configuration page). You can set a filter format for this, so make sure to use one that allows links.





相关问题
Drupal Multi-language: Simple strings not translated

I m adding additional languages to a Drupal site that I m building. Getting the translation of content working is fairly easy using the Internationalisation module. Yet, simple things such as date ...

Setting up a WYSIWYG editor for Drupal site users [closed]

Looking through the Drupal contrib modules, and after a few Google searches, it becomes evident that there are any number of choices and combos available to set up a WYSIWYG editor in Drupal. I m ...

Change size of user/password login box

I don t know how to change the size of the login username/password boxes on the drupal site that I m trying to build. I m stumbling through the theming, and don t know where to find the file that ...

How does Drupal provide an edit/review/publish model?

How does Drupal support a means to update and review a website before it is published? Does it only allow you to preview a page at a time before you publish it or is there a way to create a site ...

Term for rotating header

I m looking for terminology that describes this behavior: The header of a web-page contains a different image every time you visit it. Update: It is not an advertisement, but images related to the ...

Has anyone checked out Drupal 7? [closed]

Has anyone checked out a copy of Drupal 7 yet? What do people think? I m pretty excited about the PDO and all of the designers I work with a very excited about the new admin interface/structure. Do ...

热门标签