I am working on a gallery site and I'm having issues figuring out how to accomplish this and seem to be running into walls on every search. Here's what I have going on:

Under Taxonomy (Categories), I have a vocabulary "Image Gallery" with terms "Black and White", "Color", "Portraiture", "Scenic", etc. I don't think it matters, but the Image Gallery is set for only image types, hierarchy is disabled, and only multiple select is enabled, so it will only go one level deep. I also am using the module SiteMenu to dynamically create a menu of these terms. I have clean URLs set and am using url aliases to make the links/URLs pretty (although, I can manually enter the true URL and still have the same result).

I have created a view to my satisfaction for the complete gallery page with a list view, CSS to make the list act like a table 4 wide, 2 deep with pager below. In the view, I am using a filter "Taxonomy: Terms for Image Gallery" "Is one of" with all values selected. Everything here looks wonderful. (Default, of course, lists each image node in a vertical column.)

Now, I want to do the same for each of my terms. However, I do not want to build a new view for each term. Rather, I would like to build a view that takes an $arg and will only include on the page the terms for that $arg (taxonomy/term/$arg). That way, when I want to add a new term, the view and SiteMenu builds dynamically. Sidenote: I am hoping this will still work with url aliases. But, I'll take what I can get.

Perhaps I am going about this the wrong way. Do I need views? (I thought that would be the easiest/correct way.) Or, should I be creating a new node type mygallery.tpl.php, or what? Sorry if this seems inexperienced, but I am still working through my growing pains of using Drupal.

thanks,

david

Comments

Stol’s picture

Hi

These are two essential steps for working with arguments:

  1. In the page block, enter "galleries/$arg" for URL ("galleries" can be replaced by anything in fact)
  2. In the arguments block, select "Taxonomy: Term Name" (in your case) as argument and add the argument

Save and test your view, add "galleries/Color" to your URL (don't forget to encode the white spaces in URLs, for example "galleries/Black%20and%20White").

Hope this helps

Stol

dcasey’s picture

Hi Stol, thanks for the reply. When I browse to the page, http://example.com/taxonomy/term/7 which is my Color Gallery, or http://example.com/color which is the url alias, I get a "Page Not Found". If the view is not there, I get the default single column look for both URLs.

I have "taxonomy/term/$arg" set for the URL in the page block.
For arguments block, I have "Taxonomy: Term Name", "Return Page Not Found", all other text boxes are empty. I also tried TermID and VocabularyID. I have tried modifying the Option box to 0, 1, and 10 with the same result. I am not sure if I should put anything in those four boxes. The rest of the view is constructed nearly the same as the complete gallery except that I am not using any filters. If I do add the filters, which doesn't seem like the right thing to do, I have the same "Page Not Found" result.

Like I say, since this is my first attempt at views, maybe I'm missing something obvious...

thanks,

david

=EDIT===============
I deleted the view, and I still got Page Not Found... So I added another term to see if something got screwed up. The new term worked and it appears that everything else came back in the default view. So, I went through the steps again. I am not getting the "Page Not Found" result anymore, I am only getting the default view with Title, Submitted, Terms, Image, Content, and Links. My Fields in the View are only Node title and Image with link.

Stol’s picture

Hi

From your explanation I understand that you don't browse to the right url. The type of the argument and the $arg part of the URL have to match.

In case you use "taxonomy/term/$arg" as URL then you should browse to http://example.com/taxonomy/term/Color when you use "Taxonomy: Term Name" as argument and not "http://example.com/taxonomy/term/7" because you can only use term id's in the url when the argument is set to "Taxonomy: Term ID".

I would not use "taxonomy/term/$arg" as URL because this will override every term taxonomy page (not only your image galleries) but instead i would use a custom one, like for example "galleries/$arg".

Your original filter setting is OK. You can also use "Taxonomy: Terms for Image Gallery".

To be continued

Stol

dcasey’s picture

Thanks for the help Stol,

I guess something just isn't working... maybe I'm missing something. Here is a screenshot of what I have set. I played with the option setting as 0 and 1. I also tried changing where $arg was -> wildcard and/or wildcard sub. I also tried changing the Default drop down settings. The collapsed blocks do not have anything set.

I set the url alias to http://example.com/gallery/color rather than http://example.com/taxonomy/term/color like you suggested. That made sense, and actually, I think I like the organization better now. I put the complete gallery as http://example.com/gallery

I know it shouldn't be this difficult...thank you so much.

david

dcasey’s picture

Ok... so I created a new view for my products (photography for sale). This is another vocabulary with only one term in it, product. The photography that is for sale gets this term, since all photography is an Image type (I can't filter by type: product). The view I created has two Filters, Node: Type is one of "Image" AND Taxonomy: Terms for Product is one of "Product".

The view worked perfectly, until I went to url aliases and redirected the taxonomy (which shows up in the category links above the image) from "taxonomy/term/10" to "product". Now the view is broken and shows the default single column include everything look.

So I guess the issue is with url aliases working with views. Is there any way around what I am up against? I assume there is since you were recommending changing the URL to "galleries/$arg".

thank you so much!

david

benma’s picture

Hi David,

to me it sounds like you're doing everything correct. The differences to what I did for my site:
- I changed the default taxonomy_term view, i.e. all my taxonomy listings use the same view (well actually two different, see below)
- I'm not using the "Image Gallery" vocabulary, which is, if I understand correctly, the default vocabulary created by the gallery module(?), and I have experienced it to behave somewhat special (don't know why)
- I'm using autopath for the url aliases
- I'm not using site menu (but I don't think it matters here)

Your observation about issues with url aliases and views might be right, though: Yesterday I added an alternative view (by using the tab menu) to the taxonomy pages. Now, the aliases by autopath for the default taxonomy view still work and look as I expected, but the path to the alternative view remains un-aliased (but also works).

I also had an issue with the breadcrumb resulting from this, i.e. showing a link called "taxonomy term" linking to .../taxonomy/term, which does not exist. I simply removed the breadcrumb, since it didn't make much sense for my site anyway...

Have a look e.g. here: http://www.marzeion.com/lofoten

Below is my exported taxonomy_term view - maybe it helps...

Ben.

  $view = new stdClass();
  $view->name = 'taxonomy_term';
  $view->description = 'The taxonomy view with a depth of 0.';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = '%1';
  $view->page_header = "";
  $view->page_header_format = '1';
  $view->page_footer = "";
  $view->page_footer_format = '1';
  $view->page_empty = "";
  $view->page_empty_format = '1';
  $view->page_type = 'bonus_grid';
  $view->url = 'taxonomy/term/$arg/gallery';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '12';
  $view->menu = TRUE;
  $view->menu_title = 'Show a Gallery';
  $view->menu_tab = TRUE;
  $view->menu_tab_default = TRUE;
  $view->menu_tab_weight = '0';
  $view->sort = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'sortorder' => 'ASC',
      'options' => '',
    ),
  );
  $view->argument = array (
    array (
      'type' => 'taxid',
      'argdefault' => '1',
      'title' => '',
      'options' => '0',
      'wildcard' => '',
      'wildcard_substitution' => '',
    ),
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
    array (
      'tablename' => 'image',
      'field' => 'nid',
      'label' => '',
      'handler' => 'image_views_handler_image_img_link',
      'options' => 'thumbnail',
    ),
    array (
      'tablename' => 'term_node',
      'field' => 'name',
      'label' => '',
      'options' => 'link',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'image',
),
    ),
    array (
      'tablename' => 'node',
      'field' => 'distinct',
      'operator' => '=',
      'options' => '',
      'value' => array (
),
    ),
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node, image, term_node);
  $views[$view->name] = $view;
dcasey’s picture

I'm not sure... I imported your view into my page and manually entered the URL. I would have expected it to work, but it didn't...at all. However some of your settings have clued me into a few things.

Regarding your new issue, this may be of some use: http://drupal.org/node/106460 In fact, I am wondering if it is causing me problems as well.

Thanks for looking into this. :)

david

dcasey’s picture

I dumped all my url aliases. Now if I manually enter in the URL (the one created by the view), all the views work. But, now I'm stuck with the bad taxonomy/term/# links all over my site which don't link to the view. When I change the view to accept the default URL, I lose the view...

It looks like others have been able to make this work, so I am starting to wonder if this is a new bug. Or, if there is a better way to do this without views (being that all my taxonomy view pages are the same, for this site) like templates. I just don't really know. But, I've spent a good 20+ hours on this one function (coding / clicking / researching).

If anyone has any other ideas, I would greatly appreciate them. I would like to be sure I am doing everything right before submitting an issue to the Views module.

david

My export that works by the view creating the URL:

  $view = new stdClass();
  $view->name = 'gallery_category';
  $view->description = '';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = '';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'list';
  $view->url = 'gallery/$arg';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '8';
  $view->sort = array (
  );
  $view->argument = array (
    array (
      'type' => 'taxletter',
      'argdefault' => '1',
      'title' => '%1',
      'options' => '0',
      'wildcard' => '$arg',
      'wildcard_substitution' => '',
    ),
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
    array (
      'tablename' => 'image',
      'field' => 'nid',
      'label' => '',
      'handler' => 'image_views_handler_image_img_link',
      'options' => 'thumbnail',
    ),
  );
  $view->filter = array (
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node, image);
  $views[$view->name] = $view;

My export that doesn't work with taxonomy/term/# URLs

  $view = new stdClass();
  $view->name = 'gallery_category';
  $view->description = '';
  $view->access = array (
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = '';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'list';
  $view->url = 'taxonomy/term/$arg';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '8';
  $view->sort = array (
  );
  $view->argument = array (
    array (
      'type' => 'taxid',
      'argdefault' => '1',
      'title' => '%1',
      'options' => '0',
      'wildcard' => '$arg',
      'wildcard_substitution' => '',
    ),
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => '',
      'handler' => 'views_handler_field_nodelink',
      'options' => 'link',
    ),
    array (
      'tablename' => 'image',
      'field' => 'nid',
      'label' => '',
      'handler' => 'image_views_handler_image_img_link',
      'options' => 'thumbnail',
    ),
  );
  $view->filter = array (
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node, image);
  $views[$view->name] = $view;
Stol’s picture

Hi David

Sorry, I couldn't continue yesterday afternoon and forgot about it in the evening.

In case of the first example view in your last post, the URL alias for the term "Color" would be:

"taxonomy/term/12" as URL alias and "gallery/Color" as system path

The side effect is that the URL in the browser will show "taxonomy/term/12" and not "gallery/Color". If you want to restrict access to your standard taxonomy pages I would install the "taxonomy_access" module. That way you can close every term taxonomy page individually.

Cheers

Stol

dcasey’s picture

Your suggestion worked. If I change the url alias from gallery/color to taxonomy/term/12 I get the view and all the links work. But, as you said, the browser shows the taxonomy/term/12 URL.

Now if only I could go the other direction...Shouldn't the view override the system default? I like using the argument term name, so I can put that in the title...so I like the first setting better.

Good suggestion on the taxonomy_access module... that was the next thing I was going to work on.

thanks,

david

dcasey’s picture

I just found out why it didn't work while I've been playing with Ben's exported view. I was trying to use a view name that made sense for what I was doing. My name was gallery_category when I changed it to taxonomy_term, everything worked. Because, now it is overriding the default...even though I had the default view for taxonomy_term disabled. I missed the fine print. DOH! I guess this leads me to wonder what would happen if I wanted different views based on different vocabularies...something for me to research later.

I have noticed another issue. If I browse to http://example.com/gallery I get my desired gallery page. If I browse to http://example.com/gallery/anything that should be 404 I get the previously mentioned gallery page. While I don't have any links that would show this problem, I would like to correct it.

Thanks for everyone's help!

david

dcasey’s picture

I realized that I do have two vocabularies working here...Images and Products. My image views/links all work nicely. However, when I fixed them, the new taxonomy_term override broke my custom view for Products (when I use the url alias for that particular term). Really, the only difference between the views is the Title and the Products are in my primary navigation with manually added terms (through the admin > menus, AND/OR edit view > page > menu) to filter the products in the secondary. These terms have their own view which works fine.

If the vocabulary/term fits Products, it would be nice to change the Title of the page but I've gotta figure out how to keep my secondary navigation. Unfortunately, since I have overridden the taxonomy_term, I can't duplicate a view name. I am not sure how to get this functionality...I could really use an if then else statement in the views :|

thanks

david

Stol’s picture

Hi David

I think when a view's URL overrides a system path (or not), it becomes a system path itself. I know it looks weird.

You can set the title of a view in the argument block and leave the default title input field in the page block blank.

Succes

Stol

socialnicheguru’s picture

subscribing

http://SocialNicheGuru.com
Delivering inSITE(TM), we empower you to deliver the right product and the right message to the right NICHE at the right time across all product, marketing, and sales channels.