2

Using Views, I can create a list of authors, and show the number of nodes that they have published. I've done this using aggregation. The part I can't figure out is how to filter the output based on the user profile that you're viewing. For example, if you're viewing user/1, I want you to see the number of nodes that user 1 has published.

I've tried using different uid contextual filters. In this example, I'm using "User: Uid" as the filter, and I'm trying to pull the uid from the URL by selecting "'Provide default value' > 'Use ID from URL'" in the filter's options. Since aggregation settings are on, you have to apply an aggregation type to the filter, and I'm not sure what that should be set on.

Any feedback would be appreciated. By the way, I'm using Display Suite to build the profile layout, so if there's an easier way to get want I need, I'm open for suggestions. Thanks in advance.

EDIT: For anyone attempting to do this, keep in mind that your output will not show up in the Views preview. I was forced to navigate to a user profile in order to test this. This issue seems to sprout from the combination of aggregation and contextual filters.

enter image description here

5
  • 1. Are you using D7? 2. As your title described Views: Display number of nodes published...... Are you just want to display Numbers or Titles. 3. Are you wan to make views as Block view?
    – CodeNext
    Commented Jul 28, 2016 at 20:07
  • 1. Yes. 2. In the example, I have the author field, but only for testing. The final product will only output the number of articles published by each user on their profile page. 3. Yes, I'm outputting the View as a block. That will allow me to bring it into DS as a custom field.
    – Kellen
    Commented Jul 28, 2016 at 20:17
  • I'm using Display Suite to build the profile layout, as you have described this way to change the layout, Have tried by yourself, whether it is working? Why I am asking this all, because already I am working on User profile page altering since some day. But the issue is, User profile page is generated by default, Now, Does display suit allow to make the change on that page without playing with that original path?
    – CodeNext
    Commented Jul 28, 2016 at 20:30
  • Display Suite simply overwrites the default Drupal profile page. It doesn't alter the path to the profile.
    – Kellen
    Commented Jul 28, 2016 at 20:36
  • Ok, that is the good, I will try on my trial site and will update you, if I achieve.
    – CodeNext
    Commented Jul 28, 2016 at 20:39

2 Answers 2

1

In my opinion, You do not need Display suite to achieve this. You can do this in very Simple Drupal way .

1. Your views configuration if perfectly fine. I am just posting my one for reference purpose, Where I did two changes, (1) In the pager setting, I have set the pager item to 1. (2) I removed the User: name as it is not needed.

Note: You do not need to anything with aggregation setting at filter level.

Views UI

2. From your views it is visible that you have created block.

3. Now, What you need to do is put that block in your user profile, so it looks like as a one of the field of user profile.

4. How to do that:

4.1 Place that Block under Main page content in Content region on as shown in following image.

Block

4.2 Set the display rule for this block as shown in following image. So what happens, the block are visible only on the user profile page.

Block visibility rule

4.3 Set the Role permission for the User Role, so other user can see teh profile page of other's Or anonymous users also can see teh profile page of other's: I am sure you are aware of all this.

5. Output Image: As you can see, I have tried in my Bartik theme. I have just given block title, So it can distinguished in the image. Note: I have removed User:name field from the views, as it is not necessary. The views will automatically detect from the url.

User profile

**Other example from other login **

From otehr login

Hence, this way without using any other display help, you can add the new field in the User profile. So you do not have to much play with the User profile page.

1
  • Additional Note: If you want you can put this block through Display Suit or Using Panel module, the way you want. This Block view should work with all three, as this block takes ID from url. So it should work Provided that url will have the User ID
    – CodeNext
    Commented Jul 29, 2016 at 14:08
0

Not the best approach, aggregation could get ugly if user creates 100 or 1000 nodes.

You're better off adding/creating a numeric field in User Manage Fields.

  • Use Content Access module to hide the field from edit view, so only admins can see it in the user edit form (Edit own content only ☑ Administrator).
  • With Rules when node is added/deleted, you +1/-1 the user numeric field.

    Similarly to +1 user field after comment is made

3
  • I may be able to hide the field using Display Suite. I'll do some testing tomorrow with Rules to see if I can achieve the desired result. Thanks for the tip! I'll follow up on whether or not this works.
    – Kellen
    Commented Jul 29, 2016 at 2:30
  • Following CodeNext's directions, I was able to achieve the desired output. You mentioned that aggregation could get ugly if a user creates 100 or 1000 nodes? Is there something about aggregation that I should worry about before I proceed with using it as the solution?
    – Kellen
    Commented Jul 29, 2016 at 12:51
  • Lets just say my method will always give you the optimal performance. What do you think is faster, to count how many nodes user x has? or have someone give you the answer?
    – No Sssweat
    Commented Jul 29, 2016 at 13:30

Your Answer

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

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