This tutorial is a follow up to Drupal 7 - How to use Views and Panels together
tutorial. So you might want to check it out first. We create a references field for our book content type and spit added references out in a view next to the node. We use panels to split the content area and get the node id from url.
SUMMARY
1. Get necessary modules and enable them
2. Modify the Book content type
3. Add some references
4. Create a Related Content view
5. Edit the Books page
6. Configure Related Content view some more
1. Get necessary modules and enable them
Most of the needed modules are installed in
Drupal 7 - How to use Views and Panels together
tutorial. So you can find them from there.
In addition we need the
References module
Get it from
here
.
OR
download newest version from here:
(
NOTE!
At the time 7.x-2.0-beta3 version didn't actually work right so I used the dev version
7.x-2.x-dev here.)
References module:
http://drupal.org/project/references
extract it in
sites/all/modules
and enable these components:
2. Modify the Book content type
Add new field called
References
Select list widget is propably better option than
check boxes if you have a lot's of nodes.
Autocomplete may be even better.
Choose
Book as the type that can be referenced
You propably don't want to limit the number of references, so select
unlimited here:
Now you have this if you followed from the previous tutorial:
3. Add some references
Edit some of your content and
select some references.
4. Create a Related Content view
In
FIELDS, remove the
Title and add Create
Content: References field
Remove the
label:
Apply (all displays)
Save the view and you have this:
Next, add a
CONTEXTUAL FILTER called
Content: Nid under
Advanced
Select
provide default value, choose
Raw value from URL as a
type and
2 as
Path component (that's the id number in url: books/2)
Apply (all displays)
Save the view
5. Edit the Books page
Edit the
Books page
Go to
Layout and change
Category to
Two column
Go to
Content and add the
Related Content view In the right column:
Select
Master as a display (
It really doesn't matter because our view has only one display, but here you could for example define different displays for different pages.)
Continue and Finish
Update and save your page and you should have this:
6. Configure Related Content view some more
Now go to look at your content (in books/something) which has some references and you see that
they are separated by comma, let's change this behaviour (you might want to keep it):
In your
Related Content view, edit the
Content: References field
Under
MULTIPLE FIELD SETTINGS, uncheck
Display all values in the same row.
Also we have to make the
Reference links to
point at right places:
Add
Content: Nid in
FIELDS and
Exclude it from display
Arrange it
above the
References:
Edit
Content: References field
Change
Formatter as
Title (no link) and under
REWRITE RESULTS check
Output this field as a link and set the right
Link path (Replacement patterns are found below.)
And there you have it:
You might also want to check out the
Featured Content
module, which you can also use to make blocks to relate to your content.
Did you found this tutorial useful? Please show it and use the like and share buttons! Feel free to comment as well.