Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 255 Vote(s) - 3.6 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating list of similar nodes in Drupal 7/Views 3

#1
Copy from drupal.stackexchange.com hoping to get more answers here:

I face a rather common problem of displaying a list of nodes similar to current one. Similar node is defined as one having at least one taxonomy term that current node has. There are few solutions available as modules, however the modules I've found (specifically Similar By Terms) are in beta stage (as in "not working properly") for Drupal 7.

I've also found a couple of solutions based on Views and contextual filters (such as

[To see links please register here]

) or relations. I quite like this way as it saves me installing extra modules and with Views being actively developed and supported I'd prefer to use them rather than any custom solution. The problem I can't get around is how to sort "similar nodes" by the number of terms they share. For example, if I have "IPhone 4S" Node with Terms "Gadget", "Apple", and "Phone", I want similar nodes in the following order:

1. IPhone 3 (Apple, Gadget, Phone)
2. IPad (Apple, Gadget, Tablet)
3. Mac (Apple, Computer)
4. Bramley (Apple, Fruit, Tree)

How can I sort nodes in this view by the number of terms they share?

This question is about building a view, please do not suggest module or custom php-based solutions. Thank you.
Reply

#2
I am not sure if I fully got the gist to your question but I think node queue is the answer. Check out

[To see links please register here]



The module is well developed. I have used it for a client and you can use their smartqueue api too make make your list.


Hope I was helpful.
Reply

#3
When you are configuring complex views like this one, there are some configuration tips that may help you to understand what is really going on each step:

In Structure >> Views >> Settings >> Basic:

- Check 'Show advanced help warning' (important: requires Advanced Help module installed)
- Check 'Automatically update preview on changes'
- Check 'Show information and statistics about the view during live preview'
- Check 'Show the SQL query'
- and finally, Save configuration

Now you can preview the results from each configuration step, the SQL query associated and the fields and tables involved, so you will find easier to understand how filters and aggregations work.

Hope it helps.
Reply

#4
This is an alternative solution, related to this question. However it might not apply to every case, but if you can use it it's simpler (and safer than aggregation in my opinion).

I am going to use [panels][1]. Once you create a panel to show your entity (node or anything else) you can add multiple views and show them beside the content. one of these views is going to be our related content.<br>
Thus panels is the only limitation. **Maybe** it's possible to use mini-panels and represent it as a block, I haven't tried myself.

###Prerequisites


- Views (d'oh!)
- Panels
- Views Content Pane: no need to download, It is in *ctools* module downloaded with views.
- Page manager: Same as Views Content Pane (Optional / Highly Recommended).

<br>
###The view

0. Create your view as you normally would, but do **not** create it as a block or page. Uncheck both.

1. In views configuration page create a **relation to taxonomy term** on the entity.

2. Create a **contextual filter** to filter: **Taxonomy term: Term ID**.

3. Create another **contextual filter**: *Entity ID* or **Content: Nid** if it's a node.

- While creating this one, at the bottom there is a collapsed fieldset which has the option: **Exclude**. Check it as marked.
<br><br>

5. Now by clicking *Add* create a new display of type **Content pane**.

6. In the display configuration area (named: Pane settings) open **Argument input**. You should have 2 options:

- *Content: Nid source* : Set it's source as *From context*. Set it's *Required context* as *Content ID* (if you are not using node it can be *<Entity Type> ID*.
- *Taxonomy term: Term ID source* : Set it's source as *From context*. Set it's *Required context* as *Term ID*.

Congrats! You are done creating your view. It's time for a panel (I wont explain much about creating a panel as it is beyond the scope of this Q/A).

###The Panel

1. Create a panel (or enable the node/%node default panel and add a variant).

2. In **context** tab, Create a **relation to taxonomy term** on the entity.

3. Click add content in one of panes.

4. If you didn't change the view's category, it's in *views pane* add it. It will ask for an Entity ID and Term ID both are available now in your panels context, set them.

5. Now when the panel is displayed, All the content with with the same term excluding the content on this page are displayed.

#### Views Configuration
![Views Configuration][2]

#### Contextual filter
![Contextual filter][3]

#### Argument input
![Argument input][4]


###Important P.S:
This method is tried and it works flawlessly, but at the time of writing this article ctools had a bug. There is a patch for it: [

[To see links please register here]


[1]:

[To see links please register here]

[2]:

[3]:

[4]:
Reply

#5
guess what - there are [modules][1] for that too :D

i can recommend [similar by terms][2] giving you that view without configuration hassle.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#6
1. Create a block view
2. Add Contextual filter -> Content: Nid -> Provide default value -> Content ID from URL
3. Add Relationship -> Content: Taxonomy terms on node -> specify the appropriate vocabulary
4. Add Relationship -> Taxonomy term: Content using vocabulary as specified above -> Check off Require this relationship
5. Turn on Views aggregation (NOTE: the arrow in the screenshot below is pointing to the wrong spot and should be pointing to 2 rows below where it is)
6. Assuming you are listing title only, edit the title field to use the Relationship you set up in #4 above.
7. Add new sort criteria of Content: Nid. In aggregation settings, select Count. Use relationship from #4 and sort descending
8. Add Contextual filter -> Content: Nid -> Use relationship from #4 -> Provide default value - Content ID from URL -> Scroll down and expand "More" then check "Exclude" to remove current node from the view

** See comment by @garret-albright below for testing this in the Views UI preview. **

![Related node view][2]




[1]:

[2]:
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through