Drupal 7: Displaying nodes by grouping them based on a field - drupal

Is there a way to group nodes based on a node reference field and display them in a list.
Say, I have a content type Album, and nodes Album ABC and Album DEF of type Album. These are referenced in nodes of content type Track. How can I display all the albums with the referenced Tracks in which they are referenced as a list?
For example:
Album ABC
Track 1
Track 2
Track 3
Album DEF
Track 4
Track 5
Track 6
and so on.
I have been using Drupal only for a few weeks now, Can anyone explain the answer given below??
Thanks.

Create a view filtering on the node type = album
Set the view output style to "HTML List"
Include the node reference field as a link to node in your field list
Click "theme information" then look at the name of the file that applies to the node reference field. Create a .tpl.php file with a candidate name that's specific enough for your needs will be something like views-view--viewname--fieldname.tpl.php. Click the link for the template file in use in theme information for this field, and views will show you the code in that file. Copy & paste that code to your new file
In the new file, you'll want to write a little PHP to output your links as a list. If you enable the devel module, put in the page, and inspect what's available. One of them will be an array of links. Output that with

Try Field Group or Display Suite.

Related

Showing count of content based on the select list values Drupal 7

I have a requirement in which I need to show some content along with its count based on values in a select list. I wanted to display the allocated,released and resigned resources of a particular department in a selected date range. Using views, date range and department fields are created as exposed filters.
Created a content type for creating resources. The Resources content type is having action as a select list with values allocated,released,resigned. Department is another select list and date field is also added.
Please help me with an answer if views module is not enough. Provide some other solutions also. I'm using Drupal 7.
I figured out how to show node count in views. In my view I’ve some exposed filters and passed my select list cck field as contextual filter. If no result available I made the view to display summary as row count. In the template file, I’m planning to do some calculations for showing the resources count in and out of the project. Please correct me if there is anything wrong in this approach.

Drupal 7: In Views, how could I order/sort in this manner?

Say for example I am printing name tags for thousands of content nodes in one content type called “Attendee.” Each of these nodes specifies a single "Attendee" for an event, (and their respective name tag). Say these attendees also needed name tags printed out for their “friends” who are attending with them. That is no problem—these “friends” obviously need their own node with the same fields to get their own name tag, so I distinguish that they are a “Friend of an Attendee” with a simple checkbox.
Now here’s the sorting order / grouping problem: When rendering the view, I need these “friends of attendees” to appear “right after” the attendee they are going with. Is there a way for me to maybe create a new autocomplete text field to link these together and then have them output next to each other?
p.s. I am technically using the Views PDF module, but it has the basic Views functions, so if it's possible with Views, it will probably be possible with this module.
In order to group these together, you have to have some way of linking friends to the attendees. You can do this by adding an entity reference field to the content type. See https://drupal.org/project/entityreference
here are the steps:
from admin/structure/types select "manage fields" on your content type
on the "manage fields" tab, click in "Add new field", and type in a label name. say "friend of"
for "type", select "Entity Reference", and for now, choose "Autocomplete" for your widget
click save
in the field edit tab:
select Target Type: Node
under Entity Selection, set Mode: Simple
set Target bundles: ( your attendees type )
click save
go to admin/config/development/performance and clear all caches
You should now see an autocomplete field when you edit an attendee that you can use to set the friend relationship
Things normally get a bit complicated now, as you have to tell views about the relationship between attendees and their friends. If you want to keep this dead easy, you can set the primary attendees as their own "friend" ( who they are going with ) so that you can group them together easily with their companions, without having to worry about contexts, relationships, or any other fancy stuff.

Drupal 7 Views 3: Exposed Filters that search specific FIELDS

I'd really appreciate some help with this.
I'm trying to create two different exposed filters in Views. I currently have 6,000 nodes with 75 fields each inside one content type. I'm using a Page View with an exposed form in a block. I also have the Better Exposed Filters module installed.
The first one, I want to make a text box for searching terms, but have it only search my specified fields. I would have it search 3 fields (to do a search on the full name): First Name, Middle Name, Last Name. They are all in different fields. The only thing I've been able to make it search so far is EVERY TERM in a content type (where it searches every field, not just name). I did that by exposing this filter:
Search: Search Terms
The terms to search for.
The next filter I am trying to do is for the field "Graduation Class." It might be best to do search terms for this too (if I can figure out how to search ONE field, like above), but I was hoping to have a select dropdown that lists every Graduation Class. These classes in this field range from 1905-1972. When you click a year in this box, it filters the current results by that year.
This sounds pretty basic, but I can't seem to get it and would REALLY appreciate some help.
For your reference (if needed), here are the types of filters I can add. (Off topic: I'm actually not so sure what the ":format" ones exactly are). For the "Content:" filters, I'll only show the "Name" ones, because there are 73 others. Many of these filters are from the Feeds module, because that's what I used to import my nodes:
Content: First Name (field_cinfo_fname)
Appears in: node:cadet.
Content: First Name (field_cinfo_fname:format)
Appears in: node:cadet.
Content: Middle Name (field_cinfo_mname)
Appears in: node:cadet.
Content: Middle Name (field_cinfo_mname:format)
Appears in: node:cadet.
Content: Last Name (field_cinfo_lname)
Appears in: node:cadet.
Content: Last Name (field_cinfo_lname:format)
Appears in: node:cadet.
Content access: Access
Filter for content by view access. Not necessary if you are using node as your base table.
Content revision: Log message
The log message entered when the revision was created.
Content revision: Title
The content title.
Content revision: Updated date
The date the node was last updated.
Content revision: Vid
The revision ID of the content revision.
Feeds item: Import date
Filter on a Feeds Item's import date field.
Feeds item: Item GUID
Filter on a Feeds Item's GUID field.
Feeds item: Item URL
Filter on a Feeds Item's URL field.
Feeds item: Owner feed nid
Filter on Feed Items by the Feed they were generated from using the Node Id of the Feed Node.
Feeds log: Feed node id
Filter on a Feeds Source's feed_nid field.
Feeds log: Importer id
Filter on an importer id.
Feeds log: Log time
The time of the event.
Feeds log: Request time
The time of the page request of an event.
Feeds log: Severity
Filter on the severity of a log message.
Feeds source: Feed node id
Filter on a Feeds Source's feed_nid field.
File Usage: Entity type
The type of entity that is related to the file.
File Usage: Module
The module managing this file relationship.
File Usage: Use count
The number of times the file is used by this entity.
Page Title: Title
A Page Title alternative to the Node: Title field.
Search: Links from
Other nodes that are linked from the node.
Search: Links to
Other nodes that link to the node.
Search: Search Terms
The terms to search for.
I might be mid-understanding you but don't you want to use:
Content: First Name (field_cinfo_fname)
Content: Middle Name (field_cinfo_mname)
Content: Last Name (field_cinfo_lname)
as your filters?
I'm guessing your fields are text areas which is why you've got the :format options; 'format' is another column in the longtext field type so will be available (just like 'alt' and 'title' would be available for an image field type).
If I understand the question correctly, you've got three name fields and you want a single text box to search all three fields. The easiest way to do this is to combine those three fields into a single field that is not displayed but can be searched using an exposed filter. One option is to use the Auto Nodetitle module to make the node title a combination of the three names. (I do this a lot with personnel directories so that a given entry displays as Lastname, Firstname). Then you could search on a the node title in your exposed filter.
If using the title is not an option for your project, you could add another field to your content type, eg: full_name, and write a small module to implement hook_node_save that would simply fill in the full_name field with "first middle last" whenever a node is saved. Then remove the full_name field from the display and use it for your exposed filter.
re: graduation year: If you're using a "List (Integer)" field type, that should be no problem. If you're using a plain text field type, that makes things more difficult. If you are using plain text, you may want to redo the field so that you could do cool filters such as "graduated before 1950" type filters or using jQuery sliders to select a range of graduation years.
Hope that helps.

Error in copying the content of a cck field between 2 nodes using cck computed field

I have two content types (job_post and job_application) linked using the node reference + node reference url nodes. When I click a link in a job_post node, a new job_application node is created, so that candidates can fill out their job application. My goal is to automatically copy the content of an cck email field from the referenced job_post node to a cck email field in the job_application node.
To achieve this, I am trying to use a cck computed field, as suggested in: http://drupal.org/node/298951.
In my computed field I have placed the following code:
$node_field[0]['value'] = db_result(db_query("SELECT field_emailfieldjobpost_value FROM content_type_job_post WHERE nid=%d",$node->field_referencefieldjobapplication[0][nid]));
where the field_referencefieldjobapplication, is the node reference field in my job_application node.
In the display format box of the computed field I have:
$display = $node_field_item['value'];
I have selected the option to store it in the database as a varchar.
However, nothing seems to happen. I never see the cck field or its content both when I create or after I save a new job application (I have even tried to see it in views and failed). Any suggestion on what might be wrong?
Thanks
What I would do, is give a parameter with the link (the id of the job_post). and catch the parameter and place it in a disabled cck field.
Then write a module using the hook_node_api when a jobapplication is saved, you get the data from the job_post (using node_load) and use the data from the job-post however you want.

Drupal Views: Get nodes with the same taxonomy as the current node

I have a Content-Type with taxonomy-terms. It's a select-list, so it can have only one taxonomy - at least of that vocabulary. Now I need to build a view that lists all nodes with the same taxonomy.
Thought that this wouldn't be too hard since it sounds pretty basic. Yet I can't get it working. Any ideas? I'm trying to avoid writing a module for this.
While this was technically possible with Views 2 as described in some of the other answers, Views 3 has this integration built in.
You can create an argument for the taxonomy term id and then choose "Provide default argument". This will then give you an option for "Taxonomy Term ID from URL" and "Load default argument from node page..."
This will allow you to take the taxonomy of a page and pass that as an argument to your view block.
Note: Views 3 is currently in Alpha 3 but in my experience is at a relatively stable state and I am using it on production sites. If it has features like the one above that you find useful please use it, test it and submit bugs/patches if you encounter any issues!
This answer works in Views version 2 or higher. First you need to install Views attach ( http://drupal.org/project/views_attach ). Please read about Views attach before proceeding further. Views attach is best explained by this video http://mustardseedmedia.com/podcast/episode37
Now we get to Views attach. Please enable the views attach module before proceeding. Essentially Views attach attaches a view at the end of the node. In our case our view will be a listing of other articles with the same term.
We will essentially need to "pass" the taxonomy term of the node to the view. Let the name of your Vocabulary be called MyVocab.
Steps to make the view.
Lets call the view display_other_articles_with_same_taxonomy.
Add a display of type Node Content (available after enabling Views attach). This is a display just like block and page displays but with special ability of attaching itself to the node.
Make the following settings in the Node Content Display
Node content settings
Node types: [select the content types you are interested in seeing the list of nodes with same taxonomy term]
Build modes: Teaser, Full node
Arguments: token
Show title: No
You should select Use tokens from the node the view is attached to under Arguments. Let the token be [term-id] This is the "ID of top taxonomy term". This is very important!! Essentially you are going to be passing the taxonomy term of the node from the MyVocab (See http://groups.drupal.org/node/11788#comment-38332). If it has the lowest weight, the taxonomy vocabulary will be the first vocabulary in the taxonomy section of your node edit form. Add an argument Taxonomy: Term Id.
Add the fields you are interested in e.g. Node: Title. Make sure the Node: Title is made into a hyperlink by ticking Link this field to its Node
So what this view is going to do is:
Take the taxonomy term from the MyVocab vocabulary in the Node that is currently being viewed
Pass that as argument to the view display_other_articles_with_same_taxonomy
List all the nodes that have the same taxonomy term as the node being displayed.
Thats it!
If you're using Views 3 (currently at alpha3 at the time of writing) and you want a block (right now the articles have same taxonomy term come at the end of node body) you can do it in the following fashion:
Forget about views attach... its not required
Add a block view. It should contain the same argument, fields and filters as the instructions above for the Node Content display.
You need to modify the settings for the argument Taxononomy: Term Id just slightly: Under Action to take if argument is not present: choose [x] Provide Default Argument. Choose [x] Taxonomy Term ID from URL. Now make sure [] Load default argument from term page is unselected and [x] Load default argument from node page, thats good for related taxonomy blocks. Also [x]Limit terms by vocabulary and choose the Series vocabulary.
Make sure you name the block and put it in the appropriate region.
Note: This answer is subset of the answer I provided at How to just show NodeQueue block on included nodes? In that scenario the requirement was that the related articles are explicitly selected and listed in a particular order. Its a little more complex and uses Nodequeues which we don't need here at all.
Use relationships
Node 1 -> Relationship 1 -> Term // This will be relationships->taxonomy->term
Term -> Relationship 2 -> Node 2 // This will be relationships->node->node
Argument NID to filter NODE 1
Fields or node full view on Relationship 2 (you will see select box on field adding form, to determinate what NODE to use)
Views gives you the options to add filters. Click the plus sign in the filters area of the views admin UI, select Taxonomy from the list, check either Term or ID, and fill in the value that you need to filter by.
EDIT (for explicit instructions):
First, add the necessary fields that you want under the fields section that you want to display from the nodes that you are trying to filter such as node title, etc.
Under Arguments, click the plus sign and select Taxonomy
Check Taxonomy: Term and click Add
Click Update
In your preview area test it out by adding an argument and clicking preview. If it doesn't work, your nodes do not have attached taxonomy, your views module is corrupted, or you didn't follow directions.

Resources