0

I want to show a table (using views) displaying a list of the last node (latest pub date) for each content type.

Any ideas?

5 Answers 5

1

Use a View and code to embed that View for each content type.

To get the same View as what I created, import the View I've pasted here: http://pastebin.com/2xQx7BPs

Instead of having anything hardcoded, you can achieve this as follows:

Quick and Dirty

  • Enable the "PHP filter" module.
  • Create a Basic Page.
  • Use "PHP code" as the Text format in a Basic Page with this Body

Paste this:

<?php
    $content_types = node_type_get_names(); // get all content types
    $ct_machine_names = array_keys($content_types); // we just need machine names
    foreach ($ct_machine_names as $ct_name){ // loop through, adding them as an argument to the View
      echo views_embed_view('latest_node_by_type', 'block', $ct_name);
    }
?>

Proper Way

There are a few ways to achieve this instead of using the "PHP filter". Using a custom block in your own module isn't difficult. My favorite resource that explains this is located here: http://kahthong.com/2013/06/create-your-own-custom-drupal-block-programmatically

Follow the directions, and replace the last block with something like this:

<?php
    function _YOUR_MODULE_BLOCK_ABC_CONTENT() {
      $output = '';
      $content_types = node_type_get_names(); // get all content types
      $ct_machine_names = array_keys($content_types); // we just need machine names
      foreach ($ct_machine_names as $ct_name){ // loop through, adding them as an argument to the View
        $output .= views_embed_view('latest_node_by_type', 'block', $ct_name) . '<br/>';
      }
      return $output;
    }
?>
0

Just create a view, add the "Node: Title" Field and sort your nodes by date added.

1
  • 1
    That would show multiple nodes per content type. I'm looking for a way to only show the latest node per content type (1 node per content type)
    – jeroen
    Commented Jun 10, 2012 at 20:00
0

1.) In your views Fields include content type
2.) Then set Format as Table and group them by content type
3.) Sort them by date desc
4.) on Pager select "Display a specified number of items" and enter 1 for it to show only 1 link for the node

That should be it..

1
  • No that does not work. That way you only have 1 node and a grouping field wich repeats the type the node belongs to.
    – jeroen
    Commented Jun 11, 2012 at 16:56
0

You can achieve this by using aggregation. In the views edit screen (considering you have already configured your content type filters and fields), look under advanced (right side). Near the bottom of the list locate "aggregation:No", set it to yes. Go back to your fields and change aggregation settings according to your needs.

0

Use attachments. Create a view display that shows only 1 of a certain content type. Create 2 more attachment displays, using the same settings but change the content type on each one to whatever you need, then attach those to the original display.

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.