I have been asked to do a quick edit in a drupal install as a side-side project and I don't know anyhing about Drupal. I found the view and in header section there is custom PHP code listed as follow
<div class="hit_us">
Hit Us
</div>
I want to know where can I find the content in node/add/pagename. I just need to change a line of text. I tried looking in content section but there are 1000's of published items and I was not able to find it there.
It is a very basic question but I tried a lot to find but comes up with something else always.
I found out that the pagename is a content type and I found the help text I was looking in manage fields section. So problem solved but thanks guys for taking interest in such a trivial question.
Try this:
Create a folder in the directory sites/all/modules called stackexample. Inside
that directory, create two files: stackexample.info and stackexample.module.
Place the following code inside stackexample.info:
name = Stack Example
description = Displays a message with form values on pagename nodes.
core = 7.x
Place the following code inside stackexample.module:
<?php
/**
* Implements hook_form_alter().
*/
function stackexample_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'pagename_node_form') {
// Trigger a message if arg(3) is set to "showtheform"
// e.g. node/add/pagename/showtheform
if (arg(3) == 'showtheform') {
drupal_set_message('<pre>' . check_plain(print_r($form, 1)) . '</pre>');
}
// This example will add a custom title to the revision info area if uncommented
// $form['revision_information']['#collapsed'] = FALSE;
// $form['revision_information']['#title'] = t('CUSTOM TITLE FOR REVISION AREA');
}
}
Go to admin/modules and enable the Stack Example module.
Go to node/add/pagename/showtheform to see all the possibilities, and adapt the example
lines as needed.
NOTE: it is not advised to enable this on a production site, because no security measures
are in place and the entirety of the pagename form will be exposed to anyone with the
the permission to create a pagename node (if they know to add showtheform to the url).
HTH.. :)
Related
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;
}
I wanted to override page.tpl.php for specific content type.
I have tried these thing, nothing works for me.
page--article.tpl.php
page--node--article.tpl.php
page--node--type--article.tpl.php
page--node-type--article.tpl.php
page--type--article.tpl.php
But when I targetted specific node by number i.e. page--node--8.tpl.php it worked fine.
I think page--article.tpl.php should have worked, but I dont know why its not working.
Please tell me if I am naming it wrong. and how can I debug such things. I have heard I can use Devel module, but know nothing about it. A slight hint in right direction will be appreciated.
Thanks in advance
You have to make sure that your template can handle this ... I got a code snippet that worked for me here:
http://drupal.org/node/1089656#comment-4426790
<?php
function themeName_preprocess_page(&$vars, $hook) {
if (isset($vars['node'])) {
// If the node type is "blog_madness" the template suggestion will be "page--blog-madness.tpl.php".
$vars['theme_hook_suggestions'][] = 'page__'. $vars['node']->type;
}
}
?>
Have you remembered to clear the cache (under Administer > Site configuration > Performance) so that Drupal is 'aware' of your new file & uses this rather than the default.
See here on Clearing cached data
Also, you may need to add a preprocess hook (I haven't used D7 myself, just 5/6 — think this has changed slightly.) This post on Drupal Stack Exchange seems to give more details
I just ran into the same problem.
node--recipe.tpl.php
not
page--recipe.tpl.php
this is, of course, with a content type called 'recipe'.
ALWAYS CLEAR THE CACHE...
Go to /admin/config/development/performance and click the clear cache button. It should be the first thing you do if you've made alterations to the structure of the backend and they're not showing as expected.
Otherwise you almost had it right
page--content-type-name.tpl.php
will allow you to theme the content type template.
I know this is an old question but if others arrive here, the way I override content types in drupal 7 is like this
node--contenttype.tpl
You will need to overwrite the specific node template for the content type if it is anything different than a Basic Page. Please check this out:
http://api.drupal.org/node/19080
Under this page copy/paste the items that are in the node.tpl.php page and overwrite it on how you want. You can access the node specifically by $node
Your template for articles would be:
node--article.tpl.php
Once this is created make sure you clear cache to ensure this works.
So depending on what you are trying to accomplish, there might be some CSS tricks that could help you out.
For instance, to override any CSS rules for a specific node type just remember that your pages for that node type will have a body class of "node-type-[TYPE]" (ie: .node-type-article)
You can then override the CSS as follows:
body.node-type-article #selector {}
Step 1.create a content type for example: my content type is "fullwidthpage"
Step 2. copy page.tpl.php and rename to page--fullwidthpage.tpl in template folder.
Step 3. Add this code to template.php
function <strong>YOUR_THEME_NAME_HERE</strong>_preprocess_page(&$variables) {
if (isset($variables['node']->type)) {
// If the content type's machine name is "my_machine_name" the file
// name will be "page--my-machine-name.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__' . $variables['node']->type;
}
}
Don't forgot to change YOUR_THEME_NAME_HERE
I have several custom content types and in one specific one I need to offer two fields, one for the href for a link, and one for the text of a link this way I can build and style it with minimal user involvement of the HTML/CSS. I also have a custom node.tpl for this content type. My problem is that drupal throws divs around each field I create that aren't in my template file for this content type (node-custom.tpl) and I can't put the href for a link with divs around it inside google.co.uk</div>"> See my problem. Maybe I'm doing this all wrong so any other ideas are welcome.
Please note I'm trying to create this site with minimum involvement of HTML/CSS access for the user. I'm aware I could hand code the link in the field.
The easiest way to do this would be to use a preprocess function in your template.php file and build the link up manually:
function mytheme_preprocess_node(&$vars) {
$node = $vars['node'];
if ($node->type = 'my_type') {
$uri = $node->field_name_of_link_field[LANGUAGE_NONE][0]['value'];
$text = $node->field_name_of_display_text_field[LANGUAGE_NONE][0]['value'];
$vars['my_link'] = l($text, $uri); // Using Drupal's l() function to render a link
}
}
Then in your node template file you'll have access to the variable $my_link which you can output anywhere, and will contain the correct HTML for the link. Finally, go to the "Manage Display" page for your content type and set the display of the two fields you no longer need to output to 'Hidden'.
There are other ways so if that's no good let me know
EDIT
Just to add, I think the easiest way to do this would actually be to install the Link module and use the provided field type instead of the two other fields you're currently using.
I've just discovered that if you want to alter a specific page (or group of pages) all you need is to add templates file to the core templates. For instance, I need to theme my /helloword page using a page--helloworld.tpl.php and node--helloworld.tpl.php template files.
Now all I get is a blank screen so I tried to write a preprocess function that adds support for custom theme files like:
<?php
/**
* Adding or modifying variables before page render.
*/
function phptemplate_preprocess_page(&$vars) {
// Page change based on node->type
// Add a new page-TYPE template to the list of templates used
if (isset($vars['node'])) {
// Add template naming suggestion. It should alway use doublehyphens in Drupal7.
$vars['template_files'][] = 'page--'. str_replace('_', '-', $vars['node']->type);
}
}
?>
I see no syntax error but I still get a blank screen. Still no luck
Is someone able to figure out what's wrong in the code/routine?
Drupal7 + Omega Sub-Theme
Kind Regards
I think there's a tiny bit of confusion here: a template file named node--type.tpl.php will automatically be called for any node which has the type type...you don't need to add the template suggestions in yourself.
There is one caveat to this, you have to copy the original node.tpl.php to your theme folder and clear your caches otherwise Drupal won't pick it up.
Also you don't want to use the phptemplate_ prefix...rather you want your function to be called MYTHEMENAME_preprocess_page.
Your code to add the page template based on the node type looks spot on, see if you still have the problem after you change your function name and clear the caches.
Hope that helps :)
I'm working on a restaurant directory site. I have restaurant details page that I need to implement gmap, slideshow, etc. So I need a specific page.tpl and Theme Developer gives the info as below
alt text http://img.skitch.com/20100708-b9af98fb8mpckai5wfpmktxwgf.jpg
but site's about us, contact us, faq, etc pages has same candidate name as page-node.tpl.php . So I can't use that :/
Why isnt there anything like page-restaurant.tpl.php
how can I solve this? Appreciate helps so much! thanks a lot!
[SORTED]
<script type="text/javascript">
window.onload = function() {
load();
}
window.onunload = function() {
GUnload();
}
</script>'
If you are just wanting to add Javascript code, you can use the CSS class provided with most themes. For example, Zen will give you
<body class="not-front logged-in node-type-restaurant two-sidebars page-restaurant">...</body>
which you can detect with jQuery as
$(document).ready() { $('.page-restaurant').Myfunction(); }
Regarding slideshow, I've had good luck with Views Slideshow, which provides a block you can just place in a region on your page.
We had a similar question yesterday.
The logic of drupal is that the page should be for the common elements of a page accross all types of page and content types. Page is the top level template, if you are trying to change that per content type you may not have seperated your theme correctly. You have node theming for differentiating between the different types of node. The format is node-[NODE TYPE].tpl.php
Have you created a content type "restaurant"? If you do this, you may find modules like gmap will help you out.
Add the following function to your template.php file. Replace "themename" with the actual name of your theme. This assumes you've created a separate content type for "restaurant" - I gather you have from the previous answers and comments. You'll get an option to use page-restaurant.tpl.php once you upload the edited template.php file and refresh the theme registry.
function themename_preprocess(&$vars, $hook) {
switch ($hook){
case 'page':
// Add a content-type page template in second to last.
if ('node' == arg(0)) {
$node_template = array_pop($vars['template_files']);
$vars['template_files'][] = 'page-' . $vars['node']->type;
$vars['template_files'][] = $node_template;
}
break;
}
return $vars;
}