A backlink is a link on another page that points to the current page. When Drupal 7 indexes content for searching, the links in the content that lead to other pages on the same site are noted and stored in a database table for reference as backlinks.
The Backlinks view displays a list of nodes that contain links to the requested node. If no node has been requested, all backlinks are listed. We're going to create another version of this view, which will provide a teaser of the node along with links to the nodes that link to it.
Carry out the following steps in order to get started:
For testing purposes, ensure that there is at least one backlink in your content.
From the Content list, select the node for which there will be a backlink. Take note of its node ID by placing the mouse cursor over its name and looking at the link information displayed, as shown in the following screenshot:
Select a piece of content in which you will add a link. In the body of that content, add the link. In the preceding example, a link to Test Page 1 would be as follows:
<a href="node/4">link to Test Page 1</a>
Run the cron
command from the admin status report. Check the admin search settings to ensure that 100% of your content has been indexed. If not, run the cron
command again. The following screenshot shows the indexing status:
Navigate to the Views page (admin/structure/views
) and click on the Enable link for the Backlinks view. Click on the Clone link that now appears for the view.
Enter teasers_with_backlinks for the view name.
Enter Displays a list of nodes that link to the node, using the search backlinks table as the view description.
Click on the Next button.
We will edit the clone we have created, and make some modifications to it to provide a new view. Carry out the following steps in order to accomplish this recipe:
Edit the teasers_with_backlinks view that we have created.
Click on the HTML List link next to Format: in the Format settings box.
Scroll down to the Master: How should this view be styled configuration box and select Unformatted, and then click on the Update button.
A subsequent configuration box, Master: Style options, opens. Click on the Update button.
Select the Page display.
Click on the + icon in the Fields box.
Scroll down to the configuration box, select Fields from the selected box. Select Fields: body, and click on the Add button.
In the subsequent configuration box, and clear the Label textbox, ensure that the Formatter select box contains Summary or trimmed, and click on the Update button.
Click on the node/%/backlinks link for Path in the Page settings box, change the URL to node/%/teasers-with-backlinks
, and click on the Update button.
Click on the Tab: What links ... link for Menu in the Page settings box. Change the Title textbox contents to A peek at what links here. Enter 99 in the Weight textbox and click on the Update button.
Select Block display and click on the What links here link in the Block settings box. Change the contents of the textbox to Teasers of what links here and click on the Update button.
Click on the Save button.
We can view the altered node page by viewing the node that we know has other content linking to it; the example here is node/4
:
Click on the link A peek at what links here (shown in the preceding screenshot) and you will be shown a teaser for each of the pieces of content that link to the one you were viewing, as shown in the following screenshot:
This is an example of a Node view. The original view adds a tab to the node view, What links here, which gives a list of other nodes that link to the node being viewed. We added the node body as another field, which additionally displays a teaser for each of the nodes containing backlinks.