1

I have a view that lists the terms in a specific vocabulary. I can also mark the terms if there is a new content tagged with this term. My view looks like this:

  • Term 1
  • Term 2
  • Term 3 (new)
  • Term 4
  • Term 5 (new)
  • ...

However, what I would like to achieve is a view that shows the count of the new contents tagged with a term. Like this:

  • Term 1
  • Term 2
  • Term 3 (2 new)
  • Term 4
  • Term 5 (7 new)

My current views configuration is like following:

  1. Showing taxonomy terms of a specific vocabulary
  2. Added a relationship of Taxonomy term: Content using my vocabulary
  3. Added field Content: Has new content: This has caused duplicate rows for the terms that has more than one new content. For example, if a term has three new contents, it was listed three times. So I did the next step.
  4. Activated Aggregation, and set the aggregations settings of the field Content: Has new content to SUM: This has solved the duplicate rows issue, but it doesn't show the sum of the contents as I actually wanted to achieve.

Is there any possibility that I can show the number of new contents on this view?

1 Answer 1

3
+50

Solution A: Use Views Field View

Using the Views Field View module it is possible to embed the results of one view into another view.

First create a view for nodes without a page/block (you only need the master display) and name it New content count by term. Add a context filter Content: Has taxonomy term ID. Ensure that only the Nid is listed in the fields section, add the filters Content: Published (Yes) and Content: Has new content, then enable aggregation, choose Count from the Aggregation settings of the Nid field and finally remove any pagers.

Settings for New content count by term view

Now you may embed the New content count by term view into your principal view (taxonomy terms) by adding a "Global: View"-field (provided by the Views Field View module). In order to specify the tid-parameter of the embedded view, make sure that the Term id is also exposed as a field in the principal view. If you do not want to show it to the end user, just choose Exclude from display in the field settings. After the output of the tid field can be used as a parameter (token [tid]) for the embedded view.

Solution B: Use hook_views_query_alter

There is a function in the forum module responsible of returning the number of new posts on a topic (term) on behalf of a given user (_forum_topics_unread). Use this query as a starting point for your own implementation of hook_views_query_alter.

I recommend to go for solution A and only try to implement B when performance is degraded beyond acceptable limits.

4
  • Thanks for your answer znerol. I'd like to go for solution B, would you like to expand it a little bit? Dec 30, 2013 at 12:51
  • I've succeeded it using the Solution A, even if it impacts the performance. I would be very glad if you could expand the solution B with some example about how to implement hook_views_query_alter to get the new node count. Dec 30, 2013 at 21:06
  • @ЕлинЙ. I think that solution B very much depends on the actual view. Therefore it is somewhat difficult to write up a short generic solution which is also relevant to other folks than you.
    – znerol
    Jan 2, 2014 at 14:46
  • Ok, thanks though for the Solution A. I've awarded you the bounty. I'll perhaps start a new bounty for this question to get an answer for Solution B, which is better for performance. Jan 2, 2014 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.