custom html in drupal subtheme - drupal

I'm just starting out with drupal and need some custom html for an intricate menu system. My plan is to override the html-generating functions in template.php.
My theme name is "Drupal subtheme" and the navbar I would like to target has the machine name "menu-usm-navbar-small". What should I name the functions that overrides the default html-printouts?
I think I have tried every possible combination of these. Some examples of what I've tried:
function drupal_subtheme_menu_link($variables) {
return "foo";
}
function drupal_subtheme__menu_usm_navbar_small($variables) {
return "foo";
}

If you want to place custom HTML inside, why do you need to do it trough Drupal's functions?
Let's say, that you want to insert your code into page.tpl.php (most likely) - just open that file, edit it, add your code there.
Since you are overriding some theme - copy that file from original theme, and then edit it (don't forget to clear the cache).

Related

Wordpress: Override php file in plugins include folder

I am trying to override the php file under wp-content/plugins/salient-core/includes/nectar_maps/nectar_cta.php because I need to customize some options in the returning array.
Therefore I tried to place a php file in my child theme under wp-content/themes/salient-child/salient-core/includes/nectar_maps/nectar_cta.php which doesn't work.
Also I figured out that the file is used in wp-content/plugins/salient-core/includes/nectar-addons.php as follows:
class WPBakeryShortCode_Nectar_Cta extends WPBakeryShortCode {}
vc_lean_map('nectar_cta', null, SALIENT_CORE_ROOT_DIR_PATH . 'includes/nectar_maps/nectar_cta.php');
Then I tried to use vc_lean_map with my path in functions.php:
vc_lean_map('nectar_cta', null, 'mypath');
Which also failed.
Is there any way to override this file in my child theme?
Unfortuntately, filepath overriding in the manner you're desicribing works great for child-theming, but there is no analogue for plugins.
However - you're barking up the right tree!
From the vc_lean_map() page in WPBakery1 docs:
vc_lean_map()
Map new shortcodes to WPBakery Page Builder with “lazy” method. It means that attributes for shortcode will be built only when a system uses any data from mapped shortcode or shortcode is rendered in a content of the page(do_shortcode called).
This tells me that you're able to specify a new file to override the plugin file with, and that you're likely just calling it too early in your functions.php file.
Try something like this, to be sure that you're overriding after the visual composer plugin's done loading, so it doesn't overwrite your work. (A lower priority of 100 in the example, to be explicit about the intentions.)
<?php
// funcitons.php
add_action('plugins_loaded', function() {
vc_lean_map('nectar_cta', null, 'yourpath');
}, 100);
1 WPBakery are the folks behind Visual Composer, which somehow ties into this salient theme you're using.

Wordpress when/where is the theme loaded?

I'm integrating wordpress into another application by calling
require("../wp-blog-header.php");
I would like to be able to specify the theme to use based on some conditions before the wp-blog-header.php file is called. Is there a constant, function or variable that I can use to set the theme directory to something different than is already set?
I'm trying to find where Wordpress sets the theme directory to use before it loads the templates, etc. so that I can change it on the fly if necessary.
Update:
I tried adding this in an activated plugin:
add_filter('template', 'change_the_template');
function change_the_template()
{
$theme = get_theme('Twenty Eleven');
return $theme['Template'];
}
But that didn't change it to display with the Twenty Eleven template which is different than the one set in the admin...
The code you have, changes the template but you will also have to change the stylesheet for the theme.
Add the following code along with what you already have(in activated plugin).
add_filter('stylesheet', 'change_the_stylesheet');
function change_the_stylesheet()
{
$theme = get_theme('Twenty Eleven');
return $theme['Stylesheet'];
}
This should solve the problem.

Drupal7: Trying to theme a specific page using a preprocess function, but...I get a blank screen instead

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 :)

Why is Drupal not aware of my template file?

this is a question how to override themable items in Drupal 6.
According to the book "Pro Drupal Development", we can override themable items in two ways:
overriding via Theme functions
overriding via Template files
So for example, in order to reformat the breadcrumb, I can:
via function theme_breadcrumb($breadcrumb)
via breadcrumb.tpl.php
But on my local testing server, the second approach (i.e. via template file) is not working! I see no breadcrumbs at all, while the first approach works fine.
Any idea how could this happen? any special settings I need to configure my Drupal?
thanks!
My custom theme "greyscale":
sites\all\themes\custom\greyscale:
- breadcrumb.tpl.php
- greyscale.info
- node.tpl.php
- page.tpl.php
- style.css
- template.php
relevant file contents:
* template.php:
function phptemplate_preprocess_breadcrumb(&$variables) {
$variables['breadcrumb_delimiter'] = '#';
}
breadcrumb.tpl.php:
Theme functions are setup to either use a template or a function to generate the markup, it will never use both as that's pointless.
For a theme function to use a template, it must be defined when you define it in hook_theme.
A template + preprocess function and a theme function really does the same thing: produce markup. It depends on the situation which method is best to use, that's why we have two. The good thing about templates, is that it allows themers to change the markup, without know much about PHP or Drupal.
Cache
Drupal caches all templates and theme functions defined in your theme, when you create new ones, you need to clear the cache, this can be done by:
Use drush
Clearing cache in admin/settings/performance
Use devel to clear it on each page load. Usable during development, biut will kill performance.
Switching theme back and forth will work too, but it really not the desired way to do it.
I personally always find it easier to alter breadcrumbs through template.php using hook_breadcrumb()
function mytheme_breadcrumb($breadcrumb) {
$sep = ' > ';
if (count($breadcrumb) > 0) {
return implode($breadcrumb, $sep) . $sep;
}
else {
return t("Home");
}
}
Any particular reason why you wish to use a .tpl.php file?

Drupal Features include Theme

Is it possible to include a theme in a Drupal Feature? if so how?
Not at the moment, unfortunately. Features basically consist of things that can be cleanly exported out of and imported into Drupal via various event hooks. Themes are an entirely different animal.
Theoretically, if you want to override some markup in your Feature (custom tpl.php files for your own content type for example), you could include the custom tpl.php file and use theme-related hooks in the Feature's module file to let Drupal know that the templates are in your module's directory.
In addition to Eaton's answer. If you need to override an existing template (a .tpl.php file) provided by another module you can use hook_theme_registry_alter in YOUR_FEATURE.module:
function YOUR_FEATURE_registry_alter($theme_registry) {
$originalpath = array_shift($theme_registry['TEMPLATE']['theme paths']);
$featurepath = drupal_get_path('module', 'YOUR_FEATURE') .'/themes');
array_unshift($theme_registry['TEMPLATE']['theme paths'], $originalpath, $featurepath);
}
In order for this to work, your feature should have a weight greater than the one of the module providing the overrided template. So in YOUR_FEATURE.install you will have something like
function YOUR_FEATURE_install() {
db_query("UPDATE {system} SET weight = 10 WHERE name = 'YOUR_FEATURE'");
}

Resources