display field before title node drupal 7 - drupal-7

I want to display the tag category of nodes before the title, the title field is unavailable in interface, is there a way to do that in node.tpl.php or page.tpl.php (I won't install another module like ds suite just for this purpose).
PS: I want to do this everywhere node is displayed.

You could:
In your page.tpl.php where your title is echoed wrap the title in an if statement to not display $title if you are in a node page e.g
if(arg(0)!='node'):
if ($title ):
print $title;
endif;
endif;
//print title only if i am not on node pages
and now you can print $node->title anywhere you like in your node.tpl.php
There other ways to do this in a custom module which sound more efficient, but if this is a single minor task, i guess editing your tpls is a good solution

The $content array only is available in node.tpl.php, whereas in page.tpl.php you have a $page array with already rendered children.

Related

global text into a link drupal 7

I have a view and has created fields like a title and gglobal text that contains an image.
The field title has enabled the option " Link This field to the original the piece of content" that makes it a link to the node , but want to convert the picture also a link to when you click on the image leads to the url the node .
how could I do this?
thanks
you may use the rewrite option to make image field as link in drupal views with replacement pattern.

Drupal 7 alter node display

I have a content type with two image fields, banner and logo.
I am trying to implement logic which will allow one of the two to display depending on whether an editor elected to display just the banner or just the logo from radio button options.
I setup a small custom module implementing hook_node_view and tried to unset the image field from the node object but no joy. Code fragment below:
function mymodule_node_view($node, $view_mode, $langcode){
unset($node->field_main_picture[$node->language][0]);
unset($node->field_main_picture);
$node->field_main_picture = null;
}
None of those attempts worked.
I found the answer to my question.
The node object contains an array called content which is the renderable data Drupal will print to screen.
It's in that array that my unsets need to take place. I.E:
unset($node->content['field_main_picture']);
And the main picture image disappears.
I hardly suggest you to work with Devel module when you are programming like that. It allows you to display variables in your page and visualize the tree. For example, you can call dpm($node) function in your hook_node_view() to see what's in $node and how to access it.

Rogue "?>" symbols rendering in drupal

I updated views in drupal 7 and am getting rogue "?>" symbols rendering on my pages for regions I created in a zen sub theme.
The code for one of the regions follows:
<!--/#adbanner-->
<?php if ($page['adbanner']): ?>
<div id = "adbanner" role = "banner">
<?php print render($page['adbanner']); ?>
</adbanner><!-- /#adbanner-->
<?php endif; ?>
Okay, let's try to debug this:
Start by deleting all of your content from your files (do it with a ctrl + a, ctrl + x and then paste it into a new file - this way we can be sure that ALL of the content is gone). Save the files and render the page.
If the symbols continue to pop up, it is an encoding marker that you will have to turn off. If they stop, it is not an encoding issue and we will have to try something else.
NOTE: When I say delete all of the content, make sure that you keep the structure, i.e. the calls to load any external files. Just make sure that the visible content of those files is removed.

Render individual page fields once only in Drupal 7 page.tpl.php

So I gather I can render a specific element of the $page['content'] array like so...
<?php print render(field_view_field('node', $node, 'field_image')); ?>
Where out of the box this will render the element as expected with standard defaults. Ok, so how can I make sure that hand plucked element no longer renders in the <?php print render($page['content']) ?> call later?
Why do I want something dumb like this? Because every page WILL have a header image with a few css tricks for overlays, design and such. But not every page will have attachments, links, and so on... you know, things that are additional fields in the page. So I can't manually print out each field since I don't know how many or what else there is. All I know for sure is the field_image I'm printing above is wrapped in a ton of markup for styling and must be done this way. Same for a few other fields.
Basically I'm looking for a way to unset the field immediately after use.
Does anyone know how to achieve this? I'd rather not make a view or a custom block that displays for specific pages. I eventually have to hand this over to a client who will not be able to wrap their heads around a single page being administered over many places in the CMS.
You can in fact control the display of individual fields for content types in Drupal without having to resort to the function you've used.
Since you know in advance which field(s) you want to suppress, you can turn off its display in the content type settings.
In Drupal 7, see:
Admin >> Structure >> Content types >> your content type >> Manage display
Under "Format" select < Hidden > for the field that you want to omit.
This will prevent the field contents from being displayed within the usual node contents, but field_view_field will naturally still work.
You can also fine-tune your field formats based on different view modes, e.g. choose to display the field within teasers but not in full content.
Looks like this will work:
<?php
print render(field_view_field('node', $node, 'field_image'));
MYTHEME_remove_item($page['content'], 'field_image');
?>
and in template.php file I made this function:
function MYTHEME_remove_item(&$content, $field)
{
foreach($content['system_main']['nodes'] AS $key => $val){
unset($content['system_main']['nodes'][$key][$field]);
}
}
This is ridiculous, in my opinion. I would think a system as robust as drupal would have a solution for something like this. If anyone knows the proper way to do this I will gladly mark them as correct. In the meantime, for others facing similar situations, this worked for me.

Drupal 7 not using the template suggestion

I have added the following to my template.php file, in the [themename]_preprocess_page function:
<?php
if ($variables['is_front'])
{
$variables['theme_hook_suggestions'] = array();
$variables['theme_hook_suggestions'][] = 'page__index';
}
if (isset($variables['node'])) {
// If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
$variables['theme_hook_suggestions'][] = 'page__'. str_replace('_', '--', $variables['node']->type);
}
If I run a var_dump on the $variables array, I can see that, on my front page, the 'theme_hook_suggestions' is set to only use 'page__index'. I have a file named 'page--index.tpl.php'. Drupal still uses page.tpl.php.
I also commented out the code above, and renamed the file to 'page--front.tpl.php' and it still used page.tpl.php. I clear the caches after every change.
What am I missing?
Edit: To help clarify, I want to override the entire design of the page for the front - no columns or sidebars, different graphics, different backgrounds on some of the div's, etc. I don't want to override the 'node--' template files (yet).
In the end, I need to have a static front page with a different design than the rest of the site, then a custom node template for each content type.
I worked with the awesome folks on the #drupal IRC channel and found the issue. Not sure if this is a bug in the code or on purpose - but you cannot use the word 'index' for those theme suggestions. I changed the content type's name to 'homepage' and voila!

Resources