I've been working on this issue for a few weeks now and I can't seem to get it to a point where it's reliable and complete.

I'm trying to use a view to display a bunch of results based on a taxonomy I've created. Therefore, on page example.com/music, it'll display all articles labeled "music". I've followed the instructions on this post exactly: http://drupal.stackexchange.com/a/9339. It works! Well, when I do the preview at the bottom of my window, it works. On the actual site, it doesn't display it properly.

What could be happening?

Here's what my preview looks like:
https://www.dropbox.com/s/0u6h4gux6mubk97/vp1.PNG?dl=0
As you can see, it's displaying two articles. Since there are only two articles with the taxonomy term "viewpoints", this makes sense.

Here's what my page looks like:
https://www.dropbox.com/s/nbjho76oy517ky6/vp2.PNG?dl=0
The "viewpoints" articles are present, but so are all the others. It didn't filter.

These are my settings, if that helps:
https://www.dropbox.com/s/qtkebv4c52imsna/vp3.PNG?dl=0
"Block" and "Page" have the same settings.

Any advice would be MUCH appreciated!

My actual site is http://ccdrupal.dor.org/viewpoints.

Thanks!
Brendan

Comments

Stefan Lehmann’s picture

I think what you need is something like a page path for your View which goes like: articles/%

Now your view should be loaded for all requests against articles/1 or articles/2 etc.

Then you can easily grab the ID 1,2 etc... and match it against the tid of the taxonomy term of your choice with the contextual filter settings.

And then you could put a URL alias in place which translates viewpoints to eg: articles/123 ..

I think you're just starting from the wrong end, as you're putting 'viewpoints' into the page path settings of your View, but there is actually no real argument in the end .. just a static view path.

I like cookies!

bdparker’s picture

Thanks, but I'm still having issues.

Yes, I see I should put a page path on on view. So I did! I changed my path to "/%". Not sure if I did it right, though. The preview still works, but the actual view on the page does not.

I'm looking in the URL Alias menu but I'm not sure what to do. I have some things set up, but I don't know if I'm supposed to do it for this particular view, or how I would.

Once again, I'm trying to make it so that when I visit pages, it looks for taxonomy.
ie. website.com/viewpoints loads "viewpoints"
ie. website.com/news loads "news"
ie. website.com/news/local-news loads "news -> local news"

I'm going to continue to investigate this to make it work the way I need. I'll update if I find anything.
This is what my "page information" for view "article-list" looks like now:
https://www.dropbox.com/s/h83pad6cxrmyw78/vp4.png?dl=0

Thanks,
Brendan

bdparker’s picture

Alright, I tried a bunch of other changes. Still, I didn't get anywhere.

What the heck, Drupal? I'd think this would be default functionality like other CMS programs. I can write an SQL query to display this the way I need it. I've been stuck on this for weeks. Spent hours trying to figure it out. Read forum after forum. Watched Youtube videos. I still can't find a solution. This is very aggravating. The logic is there. Why it's not working, I have no idea. It's such a small thing, but without it, the site will not do what we need it to do. I started with drupal a couple months ago. I like it, but this particular kind of problem is really souring my opinion of it.

sprite’s picture

Are you using multiple taxonomies?

Using /% with a taxonomy related view won't work.

You need to use - /taxonomy/term/% - with such a page View.

A - /taxonomy/term/% - type view also needs a contextual filter that captures the taxonomy term number represented by the % variable, and filters output using it. You may find it very helpful to deploy the pathauto module, so that the site can have user friendly aliases for the - /taxonomy/term/% - pages. Drupal knows the raw path related to each url alias. Views also aware of the difference between the path alias and the raw - /taxonomy/term/% - path for each such page.
Do you have more than one page view using - /taxonomy/term/% - page argument?

If so, you need to use the taxonomy views integration (TVI) module, which makes it possible to define a separate view to display each taxonomy.

Without the TVI module, Drupal is limited to just one page view that uses /taxonomy/term/% to display content on various pages based on the taxonomy's terms.

With the TVI module, it is possible to have one - /taxonomy/term/% - type View for each taxonomy on the site.

It remains impossible to have multiple - /taxonomy/term/% - types Views that try to employ the same taxonomy. A workaround for that problem is to make copies of a given taxonomy, with each associated with a different content type.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

bdparker’s picture

Well, I can reply to this with what I think is correct information, but I'm starting to second guess myself because it seems what I think is right isn't working.

Thanks for the help. I'll do what I can.

First, yes, I have pathauto on. Maybe that's messing me up? I have only one taxonomy. I tried installing the TVI module but, unless I'm using it wrong, it doesn't seem to do anything to help me. Youtube couldn't really show me how it works either. It has examples but it doesn't seem to relate to me at all. In all my research, I haven't even come across TVI. And I'm STILL surprised this isn't standard functionality. I must have done something odd along the way.

I have a couple views using taxonomy terms to display content. None are working correctly. I thought maybe this would cause it to break so I got rid of them and left only one. (Does disabling count as getting rid of it?) It still doesn't work. I'm enabled and disabled so many things and tried a bunch of different approaches.

Would anyone here be able to take a look at my site and tell me what I need to fix? Would it cost anything? Do we have PMs on this site so someone can send me a message to get the details?

Thanks,
Brendan

sprite’s picture

Drupal is an intensely complex software environment.

I wouldn't dane to try to actually debug such a problem long distance.

Meanwhile, yes, disabling a View is a good way to "get rid of one" temporarily. Disabling all but one View and getting that one View to work is a good diagnostic thought process.

Thankfully, Views can also be exported and imported readily. Use the export feature to make backups of your View as you make changes, so that you can version rollback or version rollforward if necessary.

If you are using a contextual filter in your View, the way in which it is defined could be the problem, when combined with other aspects of a complex view.

For all things Drupal, I keep a plain vanilla Bartik Drupal install handy in which to build proof of concept implementations of things before trying to implement them in an actual project. This helps to differentiate site specific problems from generalized feature implementation problems.

You may want to create a test version of a View concept in a plain Bartik site, with any necessary custom content types defined and so on, and try to implement it there and they re-implement the View in your actual development site.

As the years go by, as a software scientist, I have more and more concluded that Drupal is a tool for programmers who are able and willing to solve the complex problems that arise. You are not alone in your plight.

I too had some frustrating drupal problems the other week that required extraordinary measures to diagnose and debug, including resorting to inserting drupalmessage calls into code and stepping through PHP in a debugger.

Also, if you are working on a Drupal project, it helps to make extremely frequent database and code backups, dated and numbered sequentially, so that you can rollback if necessary, or to be able to install a previous version onto a test URL temporarily for diagnosis. I keep both a local XAMPP setup with PHP debugger capabilities, and a cloud based LAMP stack onto which I can create unlimited urls for development and testing. Both are a necessary investment for serious Drupal efforts.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

John Pitcairn’s picture

I'm assuming there is nothing special about your taxonomy vocabulary, it just has terms "music", "viewpoints", etc.

Create a new view, showing content, of type all, sorted as you wish, and create a page.

Give the page a path of categories/%. The first part of the path is required for a view page to work. It can be anything you want, but it needs to be static. The second, %, is the dynamic argument that will determine which taxonomy filter is applied. This is possibly why your existing view does not work, you can't have just a single dynamic argument as the path.

Under "advanced", add a contextual filter with "Content: Has taxonomy term id".

Now you want to be able to use the taxonomy term name as the filter, not the id number. So check "specify validation criteria".

Choose "Taxonomy term" as the validator.
Check the vocabulary you wish to filter by.
Choose "Term name converted to term ID" as the filter.
Check "Transform dashes in URL..."

Test using the preview with an argument of "music". The argument is case sensitive.

OK? Save the view.

Go to /categories/music

What you see there should match the preview.

To get the term name as the page title, check "Override title" in the argument settings, and use %2 which should grab the term name from the converted second argument.

Now, if you really don't want a static argument preceding your term name in the URL, there is a way to achieve that using Entity View Attachment module, attaching a view to the taxonomy term page (rather than using a view page), and using Pathauto to rewrite the term page path. But first verify that an ordinary view page works as above.

bdparker’s picture

OH! I may have discovered something!

(Thanks for your help by the way. It's really getting me closer to the answer.)

It seems to work only when I load that view in my browser directly, not when it's placed in a separate page. So if I have a path in my view which is "articles/%", I can go to "articles/viewpoints" and see the properly filtered content. If I set up a page at "articles/viewpoints", the view doesn't load. Instead, the page loads, and if I put the view in it, I don't see the correct results.

OOOOOOOK..... that's a step forward!

So now that I know that's what works, I need to try to still add the content to the appropriate place.

I have a content type which I call "Article List". It contains general information about a specific category and I've instructed my "blocks" area to display views in the content area when this article type is present. These views show like they should. The ones which contain contextual filters also display, but improperly.

My next question is this: Can I add a view to the content of a page and still have it display using taxonomy contextual filters?

If so, how? If not, how should I go about adding taxonomy-specific content to a page?

Thanks! I'm getting closer!
Brendan

John Pitcairn’s picture

Adding a view to a page as a block doesn't pass the arguments into the block. There are quite a few ways to skin this cat though:

If the pages you are creating always need a view on them, and are a separate content type to pages that don't, the Entity View Attachments module (EVA) may be your friend.

If not, and some of those pages shouldn't display a view, look into the View Reference module that lets you add a view as a field.

I assume you are using a content type because you need to add text, images etc to the page?

John Pitcairn’s picture

One thing about both View Reference and EVA is that you can have your page paths without the "articles" prefix and still pass the taxonomy term in as the view argument.

In EVA you use token replacement in the arguments setup, in View Reference you manually specify the term when you reference the view. I'd go with EVA first.

bdparker’s picture

Ok, I've researched both. It looks like people are telling me to use EVA or View Reference, but not both.

Ok, I'll start with EVA. I'm trying to find a tutorial which explains how to apply the details I need. I'm struggling with that a bit. It seems I'm headed in the right direction and this is the solution to my problem (thank you, again). I just need to get the logic down.

I have a content type, which is visible as a page. In this content type, I want to display three views, each which have their own properties and contextual filters. How do I use EVA to accomplish this?

Thanks,
Brendan

John Pitcairn’s picture

I'm travelling and mostly offline for a couple of days now but if you are still having difficulty after New Year give me a nudge here and I'll walk you through it.

bdparker’s picture

Thanks John! Sure, I might do that. I only have a little bit of time I plan to work on this before then, so I may.

sprite’s picture

You are giving the impression that you are making your design overly complicated.

Simplify:

Don't use static pages on your site (with a few exceptions).

Create your own content types, including what you want/need, paragraph text, images, media entities, and so on.
- create theme and CSS styling as necessary.

Each custom content type can easily display in "full" mode on their own individual pages.

Each such page can optionally have sidebar, header, footer, blocks all generate from Views. Define where the View blocks should appear using the path filter(s) in the blocks.

Build most of your content using Views of various sorts (to generate both pages dynamically and blocks dynamically). Views that generate pages can display lists or rows of teasers, or display node fields that are custom formatted using theming and CSS.

Again, Views can dynamically build the content at specific URLs using criteria defined in the content itself, including categorization using one or more taxonomies.

Keep in mind that you will want to organize your page generation views that employ - taxonomy/term/% - with one such View page per taxonomy, with the Taxonomy Views Integration (TVI) module configuring which such View is associated with each taxonomy.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

bdparker’s picture

I'd very much like to simplify if I can! But I don't know if that's possible.

I'd like the site to work so that when someone goes to an article list taxonomy page (ex. news/local), it displays a layout similar to this:
https://www.dropbox.com/s/tmuymnq4ga9djxz/example.png?dl=0

Unfortunately, it's not just a list of content. I think I need to apply four different views to accomplish this. Which means I need to "set" a content type for the page. And also, certain taxonomy article list pages will have a slightly different layout.

John Pitcairn’s picture

Relying solely on views generated pages can be great but you need to be very sure it will meet your needs in the medium term.

Using content types with attached contextual views provides more flexibility in that respect. Especially when the client decides they want to be able to add text and images above the view ... do you give them access to the views UI? Er, nope.

I've been down the all-views route and while the site began well it wasn't long before client requirements made that approach too limiting and a support nightmare.

sprite’s picture

The individual nodes don't display as views, but as their own content type node pages. Each of those can have additional blocks on them, including Views generated blocks.

Adding addition content can be done with blocks, even Views Blocks, above or below, the content of the primary Views pages.

When the Views are properly contextualized, they vastly reduce the amount of effort involved in site development and maintenance.

Taxonomy organized Views are an excellent foundation for for Drupal sites, especially very large Drupal site. Once the contextualized Views are created, they require very little maintenance.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

sprite’s picture

Yes, your observation that Drupal static pages (content type == Basic page) blocking Views generated pages is correct.

If a static page exists at a given URL a Views generated page is not going to get displayed at the same URL.

If you are going to build your site with Views generates pages; to add additional content on the Views generated pages, use blocks to display the additional content at those URLs. With the foregoing in mind, it is perfectly reasonable to display Views block views in the "content" region of a Views generated page. If your theme has additional regions, you can display your content in any or all of those theme regions. When doing so, it is perfectly reasonable to build a Views block view that displays a single node, if desired, where the content is URL context sensitive. On such pages, it is a frequent practice to create Views blocks that display context sensitive lists of additional nodes associated with the context of the primary Views output data displayed on the page. The possibilities with this type of design are extensive.

The concept here is that nearly all of your site's "pages" i.e. its URLs would be Views generated pages, not Drupal static pages. The revelation here is that Drupal static pages are rarely the best choice for construction of pages on a sophisticated Drupal site.

Your observation in this regard is also important because the existence of a Drupal static page blocking a Views page from displaying, is quite different from the original problem you asked about above. However, such a situation would also create the symptoms you described. However, all of the provisions discussed previously still apply.

By the way, whenever you have a Views dynamic URL expressed with an alias, the alias doesn't actually make any difference. For example if you have a pathauto alias URL wildcard set such as:

vocab/%

in a View, it is my understanding that expressing that path with the alias in a View doesn't change the way the view operates. The view functions as:

taxonomy/term/%

despite having been expressed with the alias. When expressed as taxonomy/term/%, if a pathauto URL alias exists for the corresponding path it will function properly.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

bdparker’s picture

Regarding your comment:

"Your observation in this regard is also important because the existence of a Drupal static page blocking a Views page from displaying, is quite different from the original problem you asked about above."

Yes, it is. I think I've started to understand the real problem and am focusing on a particular issue. I like that it's starting to get clearer, but I should probably open a new issue with the specific problem in detail.

Thanks for your detailed and clear explanation!

sprite’s picture

The multiple simultaneous views setups you are trying to build seem like you are trying to run the 3 minute 1500 meters before you've gotten walking fully mastered.

Start with really simple Views/Taxonomy configurations and make those work, one at a time, before trying to combine multiple views.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

bdparker’s picture

I agree, but it seems it's not that simple.

To continue that analogy, I learned to walk just fine, and then jog, and got a lot faster in the process. Come to find out, what I need to do takes place in a pool, and I haven't learned to swim. Unfortunately, I can't find a swim instructor, and nobody seems to know how to swim either, so I'm grabbing some floats and a paddle and trying to do whatever I can.

To explain, I got the taxonomy thing working on another instance of this website so that the articles would show on the correct pages. The Views/Taxonomy worked just fine. The problem was that I had no way of controlling the display, since I had to modify it like crazy in order to give the client what's needed. All I had working was a basic list. It wasn't a content type. It was just there. When I went to a page (any page), it would work.

It seems in order to add all the stuff I need to that page, I'm going to have to take a completely different approach (ie. swimming). From what I understand, I'm on the right track, but it seems the only thing I need to do is to have these blocks on my page obey the rules of the taxonomy in my URL.

I'm trying to get this working on my own, and I've reached out to many people for assistance. I don't think anyone has the answer - at least not yet. It sounds like they're going to try to work it out like I am. I have responses which sound good, but are incomplete, or I don't understand the explanation, or someone will suggest something that another person will discredit.

Aside from resolving this on my own, it seems I have two other options:
1.) Pay someone a small amount to get this working, though I think getting the funding and doing all the paperwork would probably be harder than getting it to work on my own. :/ That's why I haven't done that yet.
2.) Hard code it the way I need, since I can probably write the SQL and PHP in far less time than learning Drupal.

sprite’s picture

I have built Views blocks that use contextual filters, which are then correctly display on Views pages generated by taxonomy/term/% paths, and which correctly parameterize their content based on the taxonomy term in the path.. With the correct configuration, these aspects of what you are trying to do is very possible.

spritefully yours
Technical assistance provided to the Drupal community on my own time ...
Thank yous appreciated ...

bdparker’s picture

YEP! I'm sure! I'm guessing there's something somewhere conflicting with it. That, or it's not set up right, or something.

Stefan Lehmann’s picture

Just want to second Sprite's opinion here. It sounds like you're trying to build a very high house without having put a strong foundation underneath it. I think you have to learn the basics first, so you can use all the power features.

It's like that with everything. There are no shortcuts other than copy & pasting from stackoverflow or the forums here. But then you can only hope for the best, if requirements and copy / pasted code / procedure don't do exactly what you need.

I like cookies!

bdparker’s picture

Alright, here's my update. It's getting complex above so I thought I'd just start this other comment.

I think I'm on a better track. I think I need to set up a "Relationship" which can take the taxonomy term from the URL and read it in the block. I'm closer, but still not quite there. I'm also trying the contextual filter "Taxonomy Term: Term ID" instead of "Content: Has taxonomy term ID".

Now what's happening is my view is displaying all articles with a taxonomy term set to it, instead of everything.

Apparently A LOT of people were asking this online over the last 6 years but there hasn't been a solution. They either resolved it by doing something else or just stopped replying.