Get a node to show up underneath a View's menu item - drupal

So I've got a content type of "News" and then a View which shows a list of News nodes as a menu item.
Is there any way to highlight the News View in the menu tree when you're viewing a News node?
I'm sort of aware of why this doesn't work, and why doing this might be hacky, but there's got to be a way to have a "default" menu item or something that a node can show up under.

Actually, I found a module that does basically what the template.php answer above does, by allowing you to assign a default menu item by content type.
It's called Menu Trails. Here is an excerpt from its project page:
... adds some common-sense usability to Drupal's menu system
Menu Trails implements primary/secondary links which keep the current menu trail "active" or highlighted. A handy snippet ready to go into your template.php is included.
The module provides a means of broadly categorizing nodes (by type or taxonomy) as falling "under" a known menu item. These nodes are not added to the menu tree (keeping the menu admin system sane) but they will trigger the functionality above -- preserving navigation state for the user -- when viewed.
New for 6.0: Menu Trails can also set breadcrumbs for nodes, keeping them in sync with the trail.
New for 6.0: Menu Trails is now Organic Groups aware, so nodes can be designated to fall "under" the first group node they belong to.
New for 6.0: A token is exposed to pathauto (and other token-aware modules) allowing for the menu trail to be used in automatic path alias creation.

Assuming the answer to my above comment is "yes," this is something you can accomplish through the template.php file in your theme folder
The final solution will depend on your settings, but generally most of the action will happen inside phptemplate_preprocess_page
// Simplified, and untested in this form
function phptemplate_preprocess_page(&$vars) {
if (isset($vars['node'])) { // if we're looking at a node
$body_classes[] = (($vars['node']->type == 'News') || (arg(0) == 'News')) ? 'news_page' : ''; // Page is news page
}
else if (arg(0) == 'taxonomy') {
// ... Special handling for news taxonomy pages, if you want
} else {
$body_classes[] = "page-type-" . arg(0);
}
$body_classes = array_filter($body_classes); // Out! Out! Damn empty elements!
$vars['body_classes'] = implode(' ', $body_classes);
}
This will give the you the body.news_page style class to work with, and you can combine that with the style of your news menu block to make it appear how you like.

if Menutrails doesn't work (for me it didn't) you can do it yourself by something like:
$somenode = menu_get_item('node/5');
menu_set_item($somenode);

I have found you have more control if you do something like this in hook_nodeapi().
// this code worked for me
$somenode = menu_get_item();
$somenode['href'] = 'node/5';
menu_set_item(NULL, $somenode);
You may need to set the weight of your custom module to be heavier than core modules: at least 1

Related

Remove sub menus from the admin view for a plugin that registers a custom post type

I know there are 357,982 other posts about this BUT they all kinda lack something ie. an actual example that works for those of us who don't write 4,594,334 line of code every day.
SO - As it stands the scenerio is:
A plugin that registers a custom post type
A sub-menu you want to hide
What next?
The best solution I have found is actually pretty easy and requires a bit of inspection of the source and a good understanding of what to look for.
In this example woocommerce is registering the custom post type 'product' with a sub-menu that appears as 'Product Options'. We want to hide this for non-admin users.
Doing an inspection of the menu items we find that the hyperlink for the parent menu is 'edit.php?post_type=event_ticket' - looking a little further we see that the hyperlink for the sub-menu is 'https://websitename.com/wp-admin/edit.php?post_type=product&page=product_attributes'
We will use the 'add_action' hook as shown below. Please note that we are using the url for the parent menu however we are ONLY using the page parameter for the child.
add_action('admin_menu', 'remove_menu_pages', 999);
function remove_menu_pages()
{
if (current_user_can('manage_options') == false)
{
//1st parameter is parent URL | second is the 'page' parameter from the child url
remove_submenu_page('edit.php?post_type=product', 'product_attributes');
}
}
Add this to your functions.php and then login as a non-admin user and the submenu should now be hidden.

How to hide title from page node Drupal

I'm trying to remove the title of a page node on Drupal. I have this page:
And I want it to look like this:
As you can see, I want the title to be removed, but only for taxonomy terms. If I try to erase it using CSS, I erase al page-titles, so I wanted to use this module, that allows administrators to auto-generate node titles and hide it.
I go to structure -> type content -> my type content, and edit it. I activate the module, and I want to auto-generate titles depending on the node category. I think it should look like this, but it doesn't work...
Any ideas why?
EDIT: Sorry, I forgot to say: yes, when I activate the module, use it, and select the category as the auto-generated title, it works. But it doesn't hide the title...
It also launches this mistake:
Use Exclude Node Title module.
https://drupal.org/project/exclude_node_title
Setting for this module:
Click on Module->Exclude node title->configure
Home » Administration » Configuration » Content authoring
Select All nodes from Basic Page
Check Full Content for hide title from all cms page except home page
Check Teaser for hide title from home page.
If you want to remove the title, you should look into overriding the page and node templates.
page.tpl.php and node.tpl.php
All you need to do is click "View Source" on both of those and copy them to your theme folder. From there you can modify both as required.
From what I can gather, you'll want to remove the print $title from your node.tpl.php.
Have the similar issue before, as far as I remember, I just added some if statement to the code:
<?php if (blah-blah-blah): ?>
<h2> <?php echo $title; ?> </h2>
<?php endif; ?>
Hope, it'll give you a clue.
Some other thoughts: you can make an if statement or rewrite it not only in page.tpl.php but create some specific page-node-type.tpl.php file and overwrite only its $title, or you can try to customize page's output via Views/Panels modules as well.
Also, could you please make more clear, what title do you want to remove? Page title or node title? And it should be removed only when you are looking nodes associated with some taxonomy term (in other words, when you are on /taxonomy/term/n page), am I right?
By using the Context module, you can add classes to the body so you can target just the taxonomy pages in CSS.
Using Context module to set body classes
Sorry guys, it was as easy as hide title tag on "manage presentation"...
You are all right on your responses, but they were not exactly what I needed... thanks!
Use Exclude Node Title module.
https://drupal.org/project/exclude_node_title
another nice solution for specific nodes, is to use the standard $title_prefix/suffix vars, which should be implemented by every theme. using the standard class element-invisible in page preprocess ..
like:
/**
* Implements hook_preprocess_page().
*/
function YOUR_THEME_preprocess_page(&$variables) {
if (isset($variables['node']) && $variables['node']->nid == 1) {
$variables['title_prefix'] = array('#markup' => '<div class="element-invisible">');
$variables['title_suffix'] = array('#markup' => '</div>');
}
}
Every page should contain a heading.
You should always maintain a structured hierarchy of headings within any web page. You should never have a blank heading or even hide it with display:none;. Hiding any content which isn’t viewable by your visitors but is by search engines is against Google’s guidelines as your intention is to only manipulate search engine results by including it. Restyle a H1 so it fits into your design is the best option.
If you still have to hide it then a better option would be to either create a template for that node, content type or page and simply not print the heading.
Or if you want to use CSS then use position:absolute so the heading doesn’t use any space where it is located in the page and text-indent:-9999px; so the text is moved off the screen and no longer visible but at least can be read by screen readers and search engines.
This is how I did it, Switch statement
// Get the name of node
$node_name = node_type_get_name($node);
// Then just add the content types you wish to exclude by overwriting the // $title object with an empty string
switch ($node_name) {
case 'Home page':
$title = '' ;
break;
case 'Event':
$title = '';
break;
case 'Offer':
$title = '';
break;
}

Drupal - Disable listing of nodes on taxonomy term page?

Is it possible to disable the normal taxonomy listing of nodes on taxonomy term pages?
The reason I need this is I want to use a view's override of taxonomy pages BUT the default views override stops a breadcrumb module working properly. So, I want to make a term view but as a block and show it on certain pages with PHP.
Thanks
Another way of doing this is using the Display Suite and Taxonomy Display module. Install them, then go to admin/structure/taxonomy/[mytaxonomy]/display.
Under "Use custom display settings for the following view modes" select "Taxonomy term page".
Then, in the "Taxonomy term page" view mode, under Term page display, select "Associated content display": HIDDEN.
Done! :)
This module claims to do just what you are seeking, but it did not seem to work despite checking the correct taxonomy to disable:
http://drupal.org/project/disable_term_node_listings
But putting the following in your theme's template.php will suppress those node listings:
function MY_THEME_preprocess_page(&$variables) {
if(arg(0) == "taxonomy" && arg(1) == "term") {
$variables['page']['content']['system_main']['nodes'] = null;
}
}
It's sort of a dirty way to do it, and you'll have to hide the pager using CSS, but it works.
This probably isn't the cleanest way but I've made a page-taxonomy.tpl.php and removed this:<?php print $content; ?> So far it seems this solution will work for my site, but I'd still like to know the proper way to do it.
If all you want to do is override the taxonomy term pages with a View, but NOT use the default view, you could create a custom module implementing hook_menu() or you could also take a look at the Taxonomy Redirect module.
From the Taxonomy Redirect page:
This module allows the administrator to change the destination of Taxonomy Term links.

Block view content relative to the page it's on in Drupal 6

I want to make a Views block's content show things that's related to the page I'm on. For example I have a content type 'Parent' that has many nodes of type 'Child' related to it, so on the 'Parent' node I want to show all 'Children' in my block.
Not that complicated but I just can't get it to work. I've been using the Node Relativity module to setup the Parent-Child relationship and then I tried adding an argument in the View to filter the Child nodes. The problem with this is I can't get the Parent ID saved from the Child node + I can't really get the ID of the page I'm on (the Parent's ID) either without using a the URL argument, which means no clean URLs.
I experimented with saving the ID of the parent as a taxonomy term for the Child nodes. The problem with this is I want the Parent-Child relationship to be setup automatically when creating a new node (by using the current page's ID as a parameter when creating a new node).
Maybe I'm looking at this from the wrong angle though... Does someone have any insight in this?
What you want is views attach so that on a given node you can show things related to that node. Check out this recipe from Mustardseed Media for making related content creation & views things rather easy.
Views attach would do it, but doesn't it attach to the node content rather than as a block?
To do it in a block, create a views block with the parent node reference id as the views argument.
Then select to provide the views default argument. With views 2 I think you can just use "Provide node id from URL". If that doesn't work then provide the argument with PHP and enter this as the php:
<?php if (arg(0) == 'yourcontenttype' && arg(1) != '') {  return arg(1); } ?>
Let me know how that works for you.

How to display a list of nodes and details of a single node in Drupal

I would like a page that displays a list of nodes (I can do this part with the Views module) and then also displays the details of a single node below the list. Ideally the details will update via Ajax when a node in the list is clicked, but reloading the page would be fine for a start.
I'm just starting to get into Drupal and the number of levels at which I can do stuff is somewhat overwhelming. For example should this be a View page with a customised block at the bottom? A page with two blocks (one for the list one for the item)? If so how would they communicate the node ID? Is there already a module that will do this for me? Maybe I should write my own module? And so on. If anyone with a better general understanding of Drupal could point me in the right direction it would be appreciated.
Edit:
Thanks for the answers so far, I think they point out that I missed out an important detail in my original question though. So, some more details:
I would like this page to effectively be a user's home page. As such my view is restricted to showing nodes that they've created. Editing the default node page would give me the problem of which node to send the user to when they log in (which may be possible I guess) and also would mean that I presumably couldn't view the node without also seeing the view?
I have been trying another tack which is to create page node which includes the View (called user_home) using some PHP. I have also set the View control to create a link for each node in the list and include the node id in that link e.g. http://localhost/drupal-6.10/?q=node/13/12 (where 13 is the node ID of the page I have created and 12 is the node ID of the item in the list).
<?php
//output the user_home view
print views_embed_view('user_home', $display_id = 'default');
?>
<br/>
<hr/>
<br/>
<?php
$queryparam = $_GET["q"];
// find the second /
$index = strpos($queryparam, '/');
$index = strpos($queryparam, '/', $index + 1);
$displayNodeId = substr($queryparam, $index + 1);
$displayNodeId = (int)$displayNodeId;
if ($displayNodeId > 0)
{
$displayNode = node_load($displayNodeId);
print node_view($displayNode);
}
?>
Now, this works, but I'm sure their's a more drupal friendly/compliant way of doing things (and the query string parsing is a nasty hack).
The canonical solution for this is to use a block in the "content top region" and the full node in content region.
The most basic way of achieving this is to simply display the node page normally and, with a theme having the content top region (Garland doesn't, Zen classic does), create a Views block containing the list you want and place it in that region. you can use the path as the argument to the View so its contents can depend on the currently displayed node. Then, define the visibility of the block to only match the conditions you want, probably to display only on node pages, or maybe on node pages of a specific content type. For this, use the PHP visibility mode for the block, and do something like
// Filter args for safety
if ((arg(0) == 'node') && is_numeric(arg(1)) {
$node = node_load(arg(1);
return is_object($node) && ($node->type == 'the_content_type_i_want');
}
else {
return FALSE;
}
That way the block will be displayed only when you want it.
If your theme does not have this feature, Panels provide a way for you to divide the page and place the view in one panel and the full node in an other one.
I would do that as following. Set Page specific visibility settings for your Views block with nodes list to be shown only on that nodes, Pathauto module can be helpful here also for managing bunch of nodes paths.
The custom pager might work for you.
http://drupal.org/project/custom_pagers
You first create a View for the pager to work on; this could be all posts by a certain user or whatever you want -- it's as flexible as any other View.
You don't need to provide forward-back links like a standard pager (and the default) -- with custom_pagers you get a $nav_array variable to play with that contains all the nodes in your view.
With that you should be able to create a table or list of links.
Generating secondary menu based on node titles

Resources