Is there any way with Views to show 'sibling' book pages? Namely, nodes with the same parent and with the same depth as the current node. I tried adding a 'Book: parent' relationship, but I didn't get the results I wanted.
$view = new view;
$view->name = 'list_sibling_book_pages';
$view->description = 'List sibling book pages';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('relationships', array(
'nid' => array(
'label' => 'Book parent',
'required' => 1,
'id' => 'nid',
'table' => 'book_parent',
'field' => 'nid',
'relationship' => 'none',
),
));
$handler->override_option('fields', array(
'title' => array(
'label' => '',
'link_to_node' => 1,
'exclude' => 0,
'id' => 'title',
'table' => 'node',
'field' => 'title',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'p' => array(
'order' => 'ASC',
'id' => 'p',
'table' => 'book_menu_links',
'field' => 'p',
'relationship' => 'none',
),
'weight' => array(
'order' => 'ASC',
'id' => 'weight',
'table' => 'book_menu_links',
'field' => 'weight',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'status' => array(
'operator' => '=',
'value' => 1,
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
'nid' => array(
'operator' => 'not empty',
'value' => array(
'value' => '',
'min' => '',
'max' => '',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'nid',
'table' => 'node',
'field' => 'nid',
'relationship' => 'nid',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('items_per_page', 100);
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
Comments
Comment #1
merlinofchaos commented'current node' is one of those nebulous things that Drupal knows lots less about than people wish it did. Usually you get information about the current node using an argument. You can set the argument default to 'node from URL' and that'll usually do a good job of filtering the view to the current node.
What you want to do is take this view you've created, and add an argument: Node: nid. Set the relationship to the book parent relationship you've set. Set the "action to take if argument is not present" to 'provide default argument' and select 'Node from URL'.
I believe that will get you the results you want.
Comment #2
mike_r1977 commentedThanks a lot merlinofchaos for your reply: it gave me a great idea on how to proceed. I tried using the 'Node from URL' default argument option, but it didn't work as:
1) the query in live preview showed me it'd use the node from url as 'parent', while I'd need it to use the node's book parent as parent:
WHERE (node.status <> 0) AND (node_book_parent.nid = 124)(where 124 is the node I need siblings of, and as such it doesn't work as parent for this purpose)
2) I heavily use aliases, so the node id would not be in the url anyhow.
However if I manage to get the node's book parent via php somehow, trying it out as argument in the live preview shows me it'd indeed get me the results I need, so thanks again.
Comment #3
mooffie commentedIn other words, you want to convert the incomming NID argument to its parent NID.
You can use a validator to do this conversion. Add the 'PHP code' validator to your argument. Note that in its description it explains that it can also be used to modify the argument.
How to find out a NID's parent NID? Google for "drupal book parent node" (see varesano's blog).
(I don't see why this should be a problem. Aliases are for the "outside" world. Drupal code doesn't really see them.)
Comment #4
merlinofchaos commentedAs mooffie said, don't worry about the aliases, at least until you know something's wrong. If you're just aliasing standard URLs, then Node from URL will work just fine.
Comment #5
mike_r1977 commentedmoofie & merlinofchaos: thank you! Using your suggestions I was able to create the view I needed. Here it is, in case somebody else needs something like it:
Comment #6
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #7
wolan commentedThanks a bunch Mike.
That view saved me 5 hours of headache!
d.o rocks somehow!
/wolan
Comment #8
lubnax commentedsubsribe
Comment #9
calte commentedSaved me a couple hours!!
Thank you so much, just thought I'd mention this still works with the Drupal 7 version of Views.
Comment #10
kevin.mcnamee@mailbox.org commentedsubscribing
Comment #11
mpa3b commentedgood thing!
thanks.
is there any way to display book contents on book page?
Comment #12
spineless commentedIn views 2 (using Drupal 7) there is a new variable to isolate the child pages under any page.
1. Create a relationship for book: top level book
2. Create a relationship for book: parent
3. Create a contextual filter for content:nid ( link the relationship "book: top level book" this this filter). In this filter select "provide default value" of type " Book root from current node".
4. Create a filter criteria "book: depth" (link the relationship "book:parent" to this filter criteria.
Comment #13
gurtner commentedThanks @spineless, I tried it and it didn't work for me :-(