OK. This must be do-able. I'm not sure where to start.

We have a site using CCK, Views etc. A content type called Artwork for paintings created by an Artist - and 300 odd nodes of that type. One of the fields for the content is a taxonomy field called 'Year' which contains a four digit year.

OK - so we want to see all artwork for a particular year - we have a view called artwork_by_year and pass in a parameter to get all nodes for a particular year. Say we lay them out in a grid, 8 at a time.

Example is at http://www.brianrice.info/search/all/results/field_int_year%3A1959 - although this is set up slightly differently.

Lovely, we can have a pager and everything if there's more than eight items for a particular year.

And we can click on a title or little picture and that'll take us to the node itself.

How can it be set now so that I can have next/previous buttons with the node which will only go through the artwork items which were in the view? In the example - all artwork for the year 1959.

I could create a view which shows only one item at a time - artwork_by_year_single_node_at_a_time. And I can pass in the year again as a parameter to show only nodes for a particular year. But loading this view would start at the first node in the view.

Could I set up something like /artwork_by_year_single_node_at_a_time/1998/start_at_node/281 ?

We can add pagers to the node but currently I only know how to set one up which cycles through all the nodes.

So - when we get to a node we can't use next/previous cos it's just a node - how would it know next/previous of which set?

So we need to load a 'set' somehow.

These artworks are categorised in many ways - by exhibition, by year, by medium (oil/watercolour etc). What is required is to have lists of these exhibitions, years etc - and when the user clicks on say the year '1998' they get to see a grid of artwork items for that year - including thumbnails etc.

What is needed further is that when a user clicks on one of the artwork items in the grid they get taken to the node - and this has next/previous buttons which only cycle through items/nodes from the year 1998.

Any help/pointers gratefully received.

Comments

shady_gun’s picture

Wow big description .. :)
try using this module ...
http://drupal.org/project/custom_pagers

bailey86’s picture

I'll look closely at the custom_pagers module.

bailey86’s picture

Could look at PHP snippet - but custom pager seems to be only related to nodes - once I'm at the node address how do we know the view/etc that was used to get there. When we get to node it's too late - we need to be at a view first probably.

CMS’s picture

i'm not sure if this would help... but u can use your year eg 1998 as a taxonomy term and create a view out if it, so if u would click on the year it would give u a page with images related only to the year 1998 ,u could then use colorbox to skip through images only from this view
hope it makes sense :)

just_fixed_it’s picture

Do you just want previous/next for a given node? Each node has one and only one year?

Maybe write 2 php db queries to get the previous & next node ids for any given node id, put them in a function, over-ride the node view, call the function inside your node view, and add a couple of links with the resultant node ids.

Would that do it for you?

Maybe if you need more options then add an extra argument on the node path, and link to this from your view rather than just the node. Read in the argument inside your mode view and do your logic there.

bailey86’s picture

I think the extra argument on node path is a possible way forward.

Basically, the artwork is categorised in many different ways, by medium, by year, by exhibition etc. These are all implemented as taxonomy terms.

We want to look at a view which shows a grid of all artwork for a particular year, say. No problem - either a view specific for year - and pass the year in as a parameter - or a view based on taxonomy term as a parameter.

The issue is that when the user clicks on a thumbnail they are taken to the node page - again no problem. However, the client wants to have prev/next buttons which only cycle through the artwork for the same year. Tricky as we're now looking at a node.

However, in the view I could possibly output the URL to the node as example.com/node/123/[taxonomy_term] or example.com/node/123/custom_pager_to_use

This would give me a node which has a custom pager which lists the required items - a real problem is that when I click on the Next item it will just display the node with example.com/node/124 and so will then not use the same pager.

just_fixed_it’s picture

Ummm .. no probs,

if your view links to 'example.com/node/123/custom_pager_type'
then your next button will need to link to 'example.com/node/124/custom_pager_type'

That should do the job then, yes?

bailey86’s picture

Hi,

I may be nearly there.

Say all content is categorised by Taxonomy terms.

In the initial view I can put a taxonomy term as an argument to make the initial (grid) view return list of items. This taxonomy id can then be added to the end of the item link field by ticking 'Output this field as a link' and putting 'node/[nid]/!1' in the link path.

Next I need to set up the PHP snippet in the custom_pager to us this last part of the path and get a list of nid's which have this taxonomy term set.

FInally, the custom_pager output needs to be altered so that the final part of the URL (after the last '/') is added to the links so that the next/previous links have the taxonomy term at the end so they get a correct pager as well.

just_fixed_it’s picture

Yep, sounds good.

In your custom node view, I'd check for another argument, and then use sql to get the node ids. Then just add the links as required.

bailey86’s picture

Basically this is the way it works.

I create a view which displays nodes in a nice grid.

I then pass in a taxonomy term id by appending it to URL and use this to limit the results to nodes which have this taxonomy term set.

Now I create field as a node link and output this field as a link and set the link path node/[nid]/!1 - this effectively means that the inputted taxonomy term id gets appended to the link created for the nodes. So I can click on a thumbnail and this links to a node - but crucially the taxonomy term used as a search term in the view has now been appended to the node URL path.

Now - this is where custom_pagers comes in. We are trying to add a pager which will cycle through the nodes which had the same taxonomy term set.

I used the PHP snippet box to return the nodes which link to the same taxonomy id as is at the end of the URL:

if (arg(2)) {
unset($nids2);

$term_required = arg(2);

$result = db_query('SELECT * FROM {node} WHERE type = "artwork" AND status = 1 ORDER BY nid');
while ($obj = db_fetch_object($result)) {

// Empty the terms to get them ready to be filled with the terms from this node.
unset($terms);

$node2 = node_load($obj->nid);

if ($node2){
foreach($node2->taxonomy as $term){

if ($term->tid == arg(2)) {
$nids2[] = $node2->nid;
}

} // for each taxonomy term.
} // Check that node loaded properly.
} // Loop through node list
} // Check there was taxonomy term in the URL.

return $nids2;

OK - so now the pager only lists the nodes we want - however, the links created by the custom_pager link to the normal node address. We need to append the taxonomy term id which we've used to the new links. So we edit custom_pagers.module:

// If there was a taxonomy term appended then we need to re-append.
if (arg(2)) {
$append_taxonomy = '/' . arg(2);
}
else {
$append_taxonomy = '';
}

// 10/110/2010 - kbailey
// $vars['previous'] = !empty($nav['prev']) ? l(t('? previous'), 'node/'. $nav['prev']) : '';
$vars['previous'] = !empty($nav['prev']) ? l(t('? previous'), 'node/'. $nav['prev'] . $append_taxonomy) : '';
$vars['key'] = t('@count of @count_total', array('@count' => ($nav['current_index'] + 1), '@count_total' => count($nav['full_list'])));

// 10/110/2010 - kbailey
// $vars['next'] = !empty($nav['next']) ? l(t('next ?'), 'node/'. $nav['next']) : '';
$vars['next'] = !empty($nav['next']) ? l(t('next ?'), 'node/'. $nav['next'] . $append_taxonomy ) : '';

Hope this makes sense to anyone who may need it!

just_fixed_it’s picture

Nice!

It may be quite a lot more efficient to do all the logic with sql though - no need for node loading, etc. (You can always cheat and just use the sql output from a query built in views.)

The ordering is just by node id? Is that what you want? Would date be better?

bailey86’s picture

The ordering may be by different values and may be set differently by page view.