Hi,

I am having a slight disagreement with the views module, and I am hoping you can shed some light on how to best resolve this conflict.

First off I am using the Category Module (with Taxonomy Wrapper installed) to allow for users to create new 'Band' pages, as a category, so when a user creates a news article, they can select the Band as a category. That part itself works.

My problem is that on the band pages I would like a block to be created that outputs the last 5 articles related to that Band, using the views module to seperate the type of articles, therefore being able to have Last 5 blogs about Band, Last 5 news about Band, etc.

I come into a conflict, because I can't figure out how to use the arguments feature of views to read the urls and display the view.

My urls are like this for the band pages : example.com/bands/example-band

I use pathauto to place all new 'band' pages under bands/

Bands in this case is also the the container for the bands/categories.

Any clues how I can set up arguements to take the bands/example-band and display only those articles tagged with 'example band'?

Any help is really appreciated!

Thanks,
Jeremy

Comments

venkat-rk’s picture

Quick answer:

Try using the NodeID of each example-band (category module makes each container and category a node) as the argument filter.

Edit: Not sure about the pathauto part- I am also experimenting with it. If you find a solution, do share!

jvalletto’s picture

Unfortunately, it didn't work, so unless I can find a way to do it, I will have to drop the idea.

venkat-rk’s picture

Okay, here is how to do it. Make sure you have blog entry enabled as a content type for your 'bands' container:

  1. Click on add view
  2. Fill in the basic information (including access control) as per your requirements
  3. Ignore the page settings
  4. Go to block settings and check 'Provide block, select 'List type', give a title for your block and specify the number of nodes the block should list - in your case, 5. If you wish, check the 'More' link checkbox and ignore the other settings for block.
  5. Go to 'Fields' setting and click on the 'Add Field' button. This will add a field with the default field of Node title selected. You don't have to give it a label. Make the default sort descending so that the latest posts come first
  6. Move on to 'Filters' and in the drop-down box for 'Add Filter' select Node:type and click on the Add Filter button
  7. In the filter fields added, choose 'Node: type is one of' and select blog entry from the list of node types that you see there.
  8. Save the filter
  9. Go to administer>>/blocks and click on the configure link next to the newly created views block.
  10. In the block visibility settings, choose 'Show this block only on the listed pages' and put bands/your-example-band-name* in the text box and save the changes. The asterisk is so that your block will appear on *all* the pages under your example-band category.
  11. Now, enable the block, choosing the placement and weight.

Visit www.yourdomain.com/bands/example-band and you should be able to see the block with the latest blog entries on the page of your example band. I have a working demonstration for you here

One funny thing I noticed is I couldn't see the block until I enabled access control for authenticated users in the basic information section of the block. This seems to be a bug in views module considering that I am uid1 and should be able to see everything.

jvalletto’s picture

Thanks, but still a few issues.

It worked fine as you had it, until I added a new post under a different band, and then that post showed up on the first example band's page; not good.

I know I can add a filter for the taxonomy term for bands: then is one of: example-band, but I don't want to have to create a new view per band, and placing each block.

Too bad their isn't a wildcard filter, where it can take the example-band argument and use it as taxonomy term for bands: is one of: (*), and then filter it based on that term. I realize the arguments feature helps to do that, but I can't find a way to get it to work with this and pathauto.

Thanks for your help,
Jeremy

jvalletto’s picture

I found a way to do it, and I would like to share it with you.

My problem with the arguements was it wasn't getting the right ones from the url that it needed to.

So using the views_build_view function, I changed that.

In the place I wanted the view to go, I simply put this.

     $view = views_get_view('bandblog');
     echo views_build_view('block', $view, array($node->nid), $view->use_pager, $view->nodes_per_page);

And I had a view created called bandblog, that had an argument set to Term: ID, which will now output any entries that has a matching taxonomy term for the specified node.

Pretty cool, eh?

Thanks for your help Ramdak, I appreciate it!

Jeremy

merlinofchaos’s picture

You can also do this using the php argument code section under the Arguments fieldset in a view. You can embed a tiny piece of context sensitive PHP code.

In this case, you'd probably want simply:

  if (arg(0) == 'node' && is_numeric(arg(1))) {
    return array(arg(1));
  }

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

venkat-rk’s picture

Glad I could be of some help. Your post not only let me exercise my views muscles, but was interesting enough for merlinofchaos to actually step in and give some code. Now, that's going to be really useful:-)

It worked fine as you had it, until I added a new post under a different band, and then that post showed up on the first example band's page; not good.

Check if the first example band is the distant parent of the band under which you added the new post. Or, it can happen if you set the depth of the first example band (which is a category) to -1 or some such thing, although the other example bands would then have to be child categories of the first band, which doesn't seem to be the case here, so it is unusual.

I also noticed that although I set the order to be descending in the block, the order was mixed.