How to Unset title ('Search results') on Search results page? - drupal

How to Unset title ('Search results') on Search results page?
I'm still noobish and I was trying this:
function mymodulename_preprocess_search_result(&$variables)
{
$variables['title'] = NULL;
}

You can not change it with a preprocess since the sentence is just a printed string in the template not a variable. So you have to alter the template.
In the templates folder of your theme, duplicate the template from /root directory of your site/modules/search/search-results.tpl.php.
And edit this file as you wish.
The theme template file will be automatically called instead of the one in the core.

You just need to change output rendering. Easy way to do this is to change search core module template file.
Go on:
\modules\search\search-results.tpl.php
In that file just delete output string or replace it with empty one. Find next line in code:
<h2><?php print t('Search results');?></h2>
You can delete whole row there or you can change it to:
<h2><?php print t('');?></h2>
NOTE:
When you change core modules you should pay attention you don't overwrite it with release which comes in new Drupal core (in case you want to upgrade your Drupal core).
If you not sure you will replace this file in future (during possible module or even entire Drupal core update) you might consider copy this file in your theme template folder. After putting that file in your theme template files folder you just need to clear the cache and that file will be called instead of one in core module.
#Laurent Thank you for your update.
Hope this helps.

Related

Drupal basic page doesn’t seem to use page.tpl.php

Title says it really. Basic pages created in Drupal don’t seem to use the page.tpl.php file as a template.
If I edit the html.tpl.php file, those changes apply to every page, and it causes errors when I load a basic page.
I have also tried to copy the page.tpl.php file and name it page—basic-page.tpl.php to no avail.
Any idea what’s going on?
Also, how do I go about changing the page_top variable to include more content?
Lastly, the default page.tpl.php file has $page variables and things like $page_top and the like.
How would I call the title from the page only and the body text of a page only?
I’m using Drupal 7 and a custom sub theme.
The aforementioned files are in the template folder of the theme and I did clear caches when I added them.
Add $conf['theme_debug'] = TRUE; in settings.php and clear cache, reload page and check view source.
It will display the template file suggestions.
page.tpl.php file common for all pages. Just print anything to the tpl and run any node of basic page as well as other content type page and check if its working or not. If page.tpl.php not working for basic page only, then check your template.php file.
For print a page title just need to use following code:
<?php print $title; ?>
For print body text you need to use following:
<?php print render($page['content']); ?>
This may depend on the theme you are using. But I guess you are actually meaning page--page.tpl.php (double dashes). Which will be taken into account after you added the following snippet to your theme's template.php. Replace MYTHEME with your theme's machine name.
function MYTHEME_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; // (double underscores)
}
}
See Template (theme hook) suggestions, where I also got above snippet from.
active theme debug for inspecting the template source and you get a different suggestions to user it (just avoid using node/nid).
commend drush to enable theme debug drush vset theme_debug 1

How to add a file to wordpress theme from apparence->editor?

How to create a new file in my wordpress theme without using ftp client ?
thanks !
Using touch(); PHP function, which creates a new file in the specified directory. This is how I suggest doing it (and admittedly, there are cleaner ways, but this will get the job done, quickly and effectively)…
Open header.php — then write this code in the very top of the file:
<?php touch('wp-content/themes/YOUR_THEME_DIR/FILE_NAME.php');?>
Replace YOUR_THEME_DIR with the directory in which your WordPress theme lives.
Then, replace FILE_NAME with the name of the file you want to create.
Once that’s all done, save Header.php and go to the homepage of your site.
As soon as the homepage loads, it will create that new template or theme file.
Source :
https://www.webmechanix.com/how-to-create-a-new-theme-file-in-wordpress-without-ftp-access/
You can use a plugin called WPIDE found here https://wordpress.org/plugins/wpide/
This plugin will allow you to edit and add folder and files in your project.

How can i edit the default drupal node view page

I am trying to edit the default page view of a node in Drupal and i found the file called node.tpl.php but even if i change it, the node page on the site isn't updated...
So how can i update the node view page so i can added some text, images etc.. ?
I guess that node_show function () { } is the one that displays the node but the code there doesn't give me enough detail on where the HTML is created so i can it
You need to copy the file to your theme's templates folder and clear the cache out before you can use this file. The original file should be at root/modules/node/
You can also set a template up for a specific content type by copying the default node.tpl.php file and renaming it to node--CONTENT_TYPE_MACHINE_NAME.tpl.php

separate js file for front page

I am working on a drupal 7 site and am very new to this. I need to create a totally separate home page from the rest of the site. I notice the head is built in the html.tpl.php file where all the scripts are loaded. I would rather not load scripts to the rest of the site that will only be used on the front page. Also I have found that drupal adds some code to the end of my script rendering it useless.
/js/image_scale.js?lwhgie"
What is going on here and how do get better control of this?
Thanks
Just to add a couple of points:
If you want to aggregate your homepage JS (which you may or may not) then you shouldn't add the stylesheets manually to the template file. You can add them in hook_preprocess_page(), something like this:
/**
* Implements hook_preprocess_page().
*/
function MYMODULE_preprocess_page(&$vars) {
if ($vars['is_front']) {
$path = drupal_get_path('module', 'MYMODULE');
drupal_add_js($path . '/MYMODULE1.js');
drupal_add_js($path . '/MYMODULE2.js');
$vars['scripts'] = drupal_get_js();
}
}
Also I have found that drupal adds some code to the end of my script rendering it useless.
/js/image_scale.js?lwhgie"
That shouldn't render your script useless. From the comments in drupal_get_js():
A dummy query-string is added to filenames, to gain control over
browser-caching. The string changes on every update or full cache
flush, forcing browsers to load a new copy of the files, as the
URL changed. Files that should not be cached (see drupal_add_js())
get time() as query-string instead, to enforce reload on every
page request.
you could create a new template called page--front.tpl.php in your theme folder and this will be your template for the homepage. Now you can add/remove any html markup you want. for more info take a look here: http://drupal.org/node/1089656 . Also, you could "tell" drupal to use your custom template file using hook_preprocess_page() in template.php file in your theme folder. See the comments on the link I posted earlier

Drupal: Translation template extractor works but the string cannot be found

I'm using Translation template extractor to extract transable strings I've added to my page.tpl.php page in my zen theme files.
I've correctly exporeted zen.pot file and overwritten the previous one. The string 'random text' contained in the t('random text') function in the template is correctly added to the file.
I've refreshed cache, refreshed the tab and run cron again.
However when I search for it in the translation interface I cannot find it and therefore I cannot translate it.
thanks
The solution was to switch the language of the page containing the string at least once to save the string.
Export a .po-file, edit it with (e.g with Poedit) save the file and import it into Drupal.

Resources