0

I know there are many similar questions but none of them gave me a correct solution for my particular requirement. In drupal 7 in taxonomy term page nodes are displayed as a row of nodes one below another. But I want the first node to be displayed with a bigger image in the first row and the rest of the nodes as two nodes per row. How can i do that programmatically.

2
  • is there going to be image for all the nodes? Oct 9, 2013 at 6:16
  • ha ha. not neccessarly sir
    – Nabil
    Oct 9, 2013 at 6:20

3 Answers 3

2

this could be done with view.

  1. Create a taxonomy view of the type page.
  2. Set the path as taxonomy/term/% this will override the default taxonomy path and will show the views page instead.
  3. Add the fields that needs to be shown in all the nodes accept the first one.
  4. Add a contextual filter of taxonomy term id.
  5. With in the pager settings give an offset 1 so that the first node is skipped.
  6. Set the Format to grid and give number of columns as 2 so that it displays in two columns

The above steps will display all the nodes except the first one in two columns.

Next we need to create a block to display the first node.

  1. With in the current view add a block.
  2. Set the pager to display only one element without the pager being shown.
  3. Add the required fields. (Image in the size you want etc.)
  4. Add a contextual filter of taxonomy term id.
  5. Now go back to the page view and add a header.
  6. Select "Global:view Area"
  7. Choose the block we created above form the drop down and tick "Inherit contextual filters."

Now your taxonomy page would display as you wanted.

1
  • Very good explained! Better than using Views Node Split module as in my answer. For the header view, though, I'd suggest to use an attachment display instead of a block, since it suits better and doesn't create one more block. Oct 10, 2013 at 5:46
0

you need to override the taxonomy-term.tpl.php here. copy the file from modules/taxonomy/ to your theme folder. Clear cache. now the one you have copied will take effect. You need to modify that.

implement a function themename_preprocess_taxonomy_term(&$vars) in your template.php. in it, $vars['content'] will contain all the nodes. Do whatever logic you want to do on it. In your case, get the first one from the array, theme it as required and store it in a separate variable say, $vars['first_node']. Unset it from the rest of the array. Now in your taxonomy-term.tpl.php file you will have two variables, $content for the rest of the nodes and $first_node with the first node html.

2
  • i wrote this code in template file function bartik_preprocess_taxonomy_term(&$vars) { $vars['first_node'] = "afhiere"; } to test and wrote <?php print render($first_node)?> in taxonomy-term.tpl.php but nothing is being displayed. am i doing something wrong
    – Nabil
    Oct 9, 2013 at 6:41
  • did that work? node_view($node, $view_mode = 'full', $langcode = NULL) function can come in handy for rendering a different view mode of the node. you can do all sorts of stuff here to display a different first node.
    – Neo
    Oct 9, 2013 at 6:46
0

You can do that with Views and Views Nodes Split modules.

Views module has a default view to override taxonomy pages which is disabled by default. You need to enable it first. Then, with the Views Nodes Split module, you can set different row style for the first X results.

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.