Basically I want to create A number of views in a single page pragmatically with each view containing nodes with a certain taxonomy term.

I created a view called mytestview and added to it a Contextual filter -> Content: Has taxonomy term ID.

then I added it to a tpl.php the code below:

  $terms = taxonomy_get_tree(6);
  $term_count = count($terms);
  for ($i = 0; $i < $term_count; $i++) {
  print views_embed_view('mytestview', $display_id = 'default',$terms[$i]->tid);

Unfortunately the view gets printed only once with the first argument being the first tid .

I would like to know how could I print the view more than one on the same page with each view having a different term id as a contextual filter and why didnt it print it more than once in the above code.

Thanks in advance .

Edit: Will basically I just fixed the code like below and now it works I dont know how come it works it just works a little insight will be great

$categories=taxonomy_get_tree(6); ?>
  foreach ($categories as $categorie) {
  print views_embed_view('mytestview', $display_id = 'default',$categorie->tid); ?>

thanks again

  • the only way I can see one working vs the other would be if the keys of the array were different, e.g. weren't 0 through length minus one. Alas, a quick look at the code suggests they are, but a drupal_set_message('<pre>' . print_r($terms, TRUE) . '</pre>'); and/or drupal_set_message('<pre>' . print_r($categories, TRUE) . '</pre>'); would certainly give you some debugging info to work with – Jimajamma Feb 10 '13 at 20:42
  • Just a note, but consider using Panels to embed multiple Views on a page as Content Pane displays in the Panel. – David Thomas Feb 10 '13 at 22:43
  • @Jimajamma will I believe that the views was printing correctly but they where above each other so I couldnt see them I think that the div solved it – Sari Feb 11 '13 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.