I want to have two view types in one view. I want to display the nodes from a taxonomy term. I want to display them in list view but I want the top one to be in full node like below.

------------------- (title)
*************** (body)
***************
***************
***************
-------------------
-------------------
-------------------
-------------------
Previous 1-2-3 Next

how can i do this? thank you.

Comments

NancyDru’s picture

vmlsd’s picture

thank you nancyw. i am sorry maybe what i described was not clear. actually i want to have something like this.

I want a view that display pages of a taxonomy term in list view sorted by descending created time. so it will display

------------------ (July 22)
------------------ (July 21)
------------------ (July 20)
------------------ (July 19)
previous 1-2-3 Next

However, I want the latest created page(the top one) to be display in full node so it will be like

------------------ (July 22)
.....................................
.....................................
.....................................
.....................................
------------------ (July 21)
------------------ (July 20)
------------------ (July 19)
previous 1-2-3 Next

how can tweak this? i cant solve this with either view bonus or view fusion.

thank you.

NancyDru’s picture

mooffie’s picture

Nancy gave you some very good guidance: you can use theming to change every detail in the output. The handbooks were updated recently to have some really good documentation for Views, so you may want to browse there.

One drawback in theming is that sometimes it means that you need to duplicate existing code, and this isn't always elegant. There's a solution to your problem that doesn't involve theming:

  1. I explained here how to eat up the first X nodes in a view --by implementing hook_views_pre_view. (in your case, X is 1.)
  2. If hook_views_pre_view returns semething --some string-- it gets prepended to the output. The code I gave returns nothing, so change it to return the node_view() of the first node in that array.
vmlsd’s picture

hi mooffie, I have looked at your post. But I dont know how to use the function. Could you show me more on this? thank you.

mooffie’s picture

You need to put this function in a module. I put it in a module named 'vhead' and uploaded it here. Downloaded both the .module and .info files and then enable the module.

The code is:


function vhead_views_pre_view($view, &$items)
{
  $the_view_name = 'myview'; // Change this to the 'internal' name of your view.

  global $pager_page_array;
  $is_the_first_page = ($pager_page_array[0] == 0); // are we on "page 1" in the listing?

  $output = '';

  if ($view->name == $the_view_name && $is_the_first_page) {
    $the_first_node = array_shift($items);
    if ($the_first_node) {
      $output .= node_view(node_load($the_first_node->nid), 1);
    }
  }

  return $output;
}

It removes the first node in the listing and outputs it in 'teaser' mode. Update $the_view_name to hold the real name of your view.

mooffie’s picture

Just for the record:

To achieve the same through theming, you'd do:

function theme_views_view_list_myview($view, $nodes, $type) {

  global $pager_page_array;
  $is_the_first_page = ($pager_page_array[0] == 0); // are we on "page 1" in the listing?
    
  $output = '';
      
  if ($is_the_first_page) {
    $the_first_node = array_shift($nodes);
    if ($the_first_node) {
      $output .= node_view(node_load($the_first_node->nid), 1);
    }
  }

  $output .=  theme_views_view_list($view, $nodes, $type);
  return $output;
}

(the '_list_' in the function name says it's a list view. Might be '_table_' as well.)

EDIT:
You know, I think it'd be easier for novices to to use this theming approach. Moreover, I don't see a real advantage to the previous approach (that of hook_views_pre_view). Just stick this code in your 'template.php'.

(hmmm.... so, should I delete my previous message? no, I'll leave it be.)

vmlsd’s picture

thank you mooffie. both methods work very well.

vmlsd’s picture

hi mooffie, I have another question. how to output the first node in 'full node' mode instead of 'teaser' mode.

mooffie’s picture

change:

$output .= node_view(node_load($the_first_node->nid), 1);

to:

$output .= node_view(node_load($the_first_node->nid), 0);

(See here.)

vmlsd’s picture

thank you. it works perfectly.

as I dont want to have the 'read more' link since it is in full node mode, i passed two more parameter values.

$output .= node_view(node_load($the_first_node->nid), 0, 0, 0);

NancyDru’s picture

You've just encountered two of the bugs I reported against 5.1 that I think are still there in 5.2.

Nancy W.
Drupal Cookbook (for New Drupallers)
Adding Hidden Design or How To notes in your database

vmlsd’s picture

i dont quite understand. may i know what the bugs are?

Summit’s picture

Curious what bugs are ment..
greetings,
Martijn

NancyDru’s picture