4

I have 2 content types (photos, videos) and both have a term reference to a "topic" taxonomy. The topic terms are showing on the node display pages and I would like to link to "/photo/%" for photos and "/video/%" for videos instead of the default "/taxonomy/term/%".

How can I do that?

2

This problem is Hard if implemented the way suggested in the question. It becomes easy with pathauto if you use two separate vocabularies: video_topic and photo_topic. Then, video_topic could have pathauto paths that start with video/% and photos can have paths that begin with photo/%.

Consider: if you use a single vocabulary, then clicking on the link video/% would show both videos and photos. Same with photo/%. If this is what you want, then perhaps the path you should use should be topic/% instead of video/% and photo/%. If you do want the results to be shown separately, then separate vocabularies are definitely the way to go.

If you want to keep your video/% and photo/% vocabularies in sync, then you could add a video topic in code every time a photo topic was clicked, and visa-versa. It's important to consider how you want your system to behave, though, as that will drive the solution and implementation that you'll want to choose.

  • thank you. I do want to use a single vocabulary. Why couldn't I just do a template mod to link to "video/%" from the video nodes and then create a view that only shows videos with that tag? Ditto for photos. Is "hacking" a term path considered bad practive? ;-) – uwe Jan 8 '12 at 22:37
  • 1
    Yes, I think that the best "Drupal way" to solve your problem would be to make taxonomy/term/% map to topic/% for your topic vocabulary, and then make photo/% and video/% paths to views that filter by content type + taxonomy term. Then you could convert from taxonomy/term/% to one of the views at page-render time, per your other question. I have an answer for that as well. – greg_1_anderson Jan 8 '12 at 23:34
  • 1
    Okay, I have replaced my incomplete answer to the other question with a correct answer. See: drupal.stackexchange.com/questions/18784/… – greg_1_anderson Jan 10 '12 at 22:53
5

My answer is going to use two modules, that are tools, not solutions. You will get the flexibility to do most anything you want with the paths, at the cost of needing to understand how the modules work. I will provide an outline of the required configuration below, there are useful videos here, and I will try to update the answer if you get stuck anywhere specific.

  1. Install and enable the Page Manager, as well as Panels
  2. Go to admin/structure/pages/add, and add a Page, with the path video/%video_term
  3. On the next page, click "Change", and pick "Taxonomy term: ID", then pick ID, or Name, as it suites you.
  4. Pick any layout, and just move on until you can click "Finish" to end the wizard. Now fill your layout with whatever content you wish.
  5. Repeat steps 1-4 for your "photo" page.

Since Drupal doesn't allow you to use a variable at the first level, you can't do /%content_type/%term, so instead we create two pages. Personally, I would opt to do something like /products/%content_type/%term, as a single page will lower your maintenance burden down the road. That however, will require understand "Variants", to accommodate two pages in one. The videos will explain that.

1

I'm pretty sure you can set this up using Pathauto. I know for a fact that you can set custom taxonomy paths. I just did for my Drupal Commerce Site.

http://drupal.org/project/pathauto

Just make sure that when you set a pattern, it doesn't overlap with a pattern you have set for another content type.

  • 1
    pathauto won't work here because the path is dependent on the term only. In my case the path will depend on the term and the content type the term is related to. – uwe Jan 3 '12 at 2:42
  • 1
    There is a discussion here which makes some sense: drupal.org/node/967136 . The way to do this, I think, would be to make a custom content type for each of these products. Then use [node:type] or the standard equivalent, in your pathauto settings. – commercebythegraceofgod Jan 3 '12 at 4:31
  • I still think this doesn't work. Every term can only have 1 alias, let's say the alias for the "green" term is "/photo/green". If I relate that term to a video node the alias will still be "/photo/green", instead of "video/green". I'm now trying it with a preprocess function: drupal.stackexchange.com/questions/18784/… Thanks for all the help! – uwe Jan 4 '12 at 2:49
1

In Drupal 6, I've done this with the pathauto module, and a quick look at the Drupal 7 code suggests it works there as well. In D6, you go to admin/build/path/pathauto and select Taxonomy term paths and change it to whatever you want so something similar should work in D7.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.