我有一个列出所有书籍的页面,例如
book 1
[description]
book 2
[description]
book 3
[description]
如果您点击book 1
,您将进入一个页面,其中包含您刚才看到的完全相同的描述,并附有目录。我宁愿点击book 1
也会把你带到第一页。
我在书模块中玩游戏,无法弄清楚从哪里开始。
答案 0 :(得分:3)
经过几个小时努力解决同样的问题后,我找到了一个很好的解决方案。 (使用Drupal 7.2) 您需要为book_navigation创建预处理挂钩。
一些改进:
我认为即使管理员用户可以访问图书顶级页面,在尝试访问其他用户的顶级网页时,也可以更加熟悉SEO重定向。
以下是代码:
/** * This preprocess hook avoids the top-level page of a book to be displayed. * Instead, if the top-level book is being requested, user is redirected to * the first child page. * This only occurs if user does not have outline permission. * Also on the first child page, the prev link to the top-level page is removed. */ function mytheme_alpha_preprocess_book_navigation(&$variables) { template_preprocess_book_navigation($variables); // normal behaviour for privileged users if(user_access('administer book outlines')) return; // redirect to first child if($variables['current_depth']==1) { $first_child_link = book_next($variables['book_link']); if($first_child_link['link_path']) { drupal_goto($first_child_link['link_path'],array(),301); } } // Remove prev link for first child // and remove up link for first level children if($variables['current_depth']==2) { if($variables['parent_url'] == $variables['prev_url']) $variables['prev_url']=''; $variables['parent_url']=''; } }
注意:我正在使用omega主题,因此钩子前缀是mytheme_alpha。