Drupal 7 theming: region error - php

this is in my theme.info file of my Drupal theme:
regions[conf_modules] = Configurator: modules
I'm using multiple templates for different node types. In one of them I'd like this region/block to show up. So I've put this in node--configurator.tpl.php:
<?php print render($page['conf_modules']); ?>
In the Drupal administration panel I have assigned a views block to the region, but on the node--configurator.tpl.php pages, the views block is not shown. Am I using render() properly? What's going wrong here? Thanks in advance!

In node templates, $page is simply a status variable that is:
True if the node is being displayed by itself as a page.
However, you can add regions to the page for specific content types through your page.tpl.php if you like. Something like below should work if placed in page.tpl.php:
<?php
if ($node->type == 'CONTENT_TYPE') {
print render($page['conf_modules']);
}
?>

Related

How hide Joomla custom field in homepage and category menu?

If I create custom field in Joomla, it's will show in homepage (featured article) and blog category menu.
I want custom fields to only show in a single article. It should be hidden in the homepage (featured articles) and blog category menu.
Where can I setting it or modify in PHP code?
The files you need to override are at \components\com_content\views\featured\tmpl\default_item.php and \components\com_content\views\category\tmpl\blog_item.php
Important : core files should be overridden in your template, and the core code left unchanged.
The fields themselves are generated by the lines
<?php // Content is generated by content plugin event "onContentBeforeDisplay" ?>
<?php echo $this->item->event->beforeDisplayContent; ?>
Note that removing these lines will also stop any other plugin which uses this area from working. As far as I can tell, the only other thing to use it is the voting system. If you need that, then you may need to write a bespoke plugin or just hide the area with CSS.
You can create the override of Layout com_fileds - field.
(copy the file render.php from components/com_fields/layouts/field/ to templatename/html/layouts/com_fields/field/)
Add two new variables and one more condition on the if condiction
defined('_JEXEC') or die;
$app = JFactory::getApplication();
$view = $app->input->getCmd('view', '');
if (!key_exists('field', $displayData) || $view != 'article')
{
return;
}

How to display webform in drupal 7 views

I created webform as block and I'm rendering in template like:
<?php print render($page['contact_us']); ?>
This working fine in .php, but in views not working.
I would say that you are rendering region that contains your block, not the block it self and you placed that block in "contact_us" region. But regions are available only in your page template.
Check out how to render block directly:
https://www.drupal.org/node/26502
So, it should be like:
$block = module_invoke('module_name', 'block_view', 'block_delta');
print render($block['content']);
And module name should be "webform". You can place this code directly in your view template, where you want your webform block rendered or in pre-precess function and then pass to your template as some variable and print it there.

Conditionally display menu for page type in Wordpress

I am relatively unfamiliar with Wordpress and I am creating a custom theme for a client. I would like to either display or remove the main menu depending on the page type. I have researched several options like removing the navigation from header.php and referencing it separately and also making the menu conditional which is preferable.
I have a custom page type in my theme called 'landing page' on which I would like the menu to be never be displayed, though it will be on every other page. Ultimately there will be a lot of these and I would rather I didn't have to intervene.
I would rather not duplicate my header.php file but I can only find reference to displaying the menu conditionally like below by page name or ID which seems ridiculous.
<?php
if (is_page('contact')){
<?php include(TEMPLATEPATH.'/headerA.php'); ?>
}
elseif (is_page('gallery')){
<?php include(TEMPLATEPATH.'/headerB.php'); ?>
}
else {
<?php include(TEMPLATEPATH.'/headerA.php'); ?>
}
?>
Rather than including files as above, I will put the whole thing into my header and just make the navigation conditional. Does anyone know how I should approach this using my custom page type landing page rather than by page name so every page created with that type will never have a menu?
Thanks
Are you talking about a Custom Post Type (CPT) or a page called landing-page?
They are completely different. See http://codex.wordpress.org/Post_Types
In any event, this will work for a custom post type or a page:
if ( !is_singular( 'custom-post-type-name-or-page-slug-here' ) ) {
get_template_part('menu');
}
It says: "If this page is not a single page or a CPT, load the file menu.php from the theme folder."
See also http://codex.wordpress.org/Include_Tags:
The get_template_part() tag includes the file {slug}.php or
{slug}-{name}.php from your current theme's directory, a custom
Include Tags other than header, sidebar, footer.

Custom template or theme (header and footer) for PDP page in Magento

We're redoing our theme in Magento to use a grid system (semantic.gs), and I've been tasked with the duty setting up the PDP page to use this new grid system template. We eventually will want this template on all pages, but for now, it's been specifically requested ONLY on the PDP page. So basically I want to set a custom theme/template (including header and footer, not just columns) that I can load on certain pages. Can anyone point me in the direction of how to go about doing this? Extensive SO and google searching has come up pretty fruitless.
So far:
I created a new layout called 2columns-left-grid.phtml in app/design/frontend/[my_interface]/[my_theme]/template/page
I modified these lines:
<?php echo $this->getChildHtml('header') ?>
and
<?php echo $this->getChildHtml('footer') ?>
To be:
<?php echo $this->getChildHtml('header2') ?>
and
<?php echo $this->getChildHtml('footer2') ?>
I duplicated header.phtml and named it header2.phtml, and duplicated footer.phtml and named it footer2.html
My questions:
Will this work, and if so, what other code do I need to modify (xml files, etc)
How can I get this template to apply ONLY to the PDP page for now?
Thanks!
Hello you can override product tag
< catalog_product_view translate="label">
/app/design/frontend/base/default/layout/catalog.xml
from into your new module layout xml

Wordpress Conditional Sidebar Section Based off of Page ID

Goal - have a section of my sidebar that is conditional depending on what page I'm on. All child pages of the selected page should also show the conditional section.
There are at least two ways to do this - 1) have all the conditional hooks and resulting code in one sidebar file and, 2) have multiple sidebar.php documents and call them based off what pages are being visited.
I've pretty much failed at both ways so far... :( I'm working on the second method right now though, because I think it might be more flexible long term. Anyway, in my page.php I replaced:
<?php get_sidebar() ?>
With
<?php
if (is_page(1997) || $post->post_parent) {
get_sidebar('sidebar-test-may12.php')
}
else { get_sidebar()
} ?>
With the hope of testing the method. What I want to happen is that if the page is page id 1997 or any of its child pages please show sidebar-test-may12.php. Otherwise show the regular sidebar. With the new code the whole page goes blank. Any suggestions or solutions for me? Seems like a common problem, but I haven't been able to figure it out yet. Thanks!
You have a few problems with your code example:
1) $post->post_parent is not being checked against anything else, so it will only return true if it is a child page (not necessarily the child of the page you want to target)
2) get_sidebar() is being called incorrectly. If you want to get 'sidebar-test-may12.php' from your theme folder, you need to call get_sidebar('test-may12')
3) You're missing semicolons after your function calls
So your code should look like this:
<?php
if(is_page(1997) || $post->post_parent == 1997) {
get_sidebar('test-may12'); //get sidebar-test-may12.php
}
else{
get_sidebar(); //get sidebar.php
}
?>
Let me know if that helps.
UPDATE: Bear in mind, $post->post_parent does NOT get the top-most ancestor ID of a child page. If you want to grab the top-level ID regardless of depth, consider doing this:
<?php
$ancestors = get_ancestors(get_the_ID(), 'page');
if(is_page(1997) || end($ancestors) == 1997)
get_sidebar('test-may12'); //get sidebar-test-may12.php
else
get_sidebar(); //get sidebar.php
?>
POSSIBLE SOLUTION: Building off your example and my proposed ancestry check, one thing you can do is have your template check to see if a special sidebar exists in your theme based on the parent page's slug. This way, if you decide a particular page needs a special sidebar for it and all of its children/grandchildren/great-grandchildren/etc. you just need to add it into your theme with a name of 'sidebar-{parent_slug}.php'. So:
<?php
$id = get_the_ID();
$ancestors = get_ancestors($id, 'page');
$top_page = $ancestors ? get_page(end($ancestors)) : get_page($id);
if(locate_template('sidebar-'.$top_page->post_name.'.php'))
get_sidebar($top_page->post_name);
else
get_sidebar();
?>
This way, you don't need a ton of conditionals to decide which Sidebar file to load on a general Page template.
Use some error trapping to show what's going on with your php, either toggling an error log in .htaccess of a simple widget: http://wordpress.org/extend/plugins/error-log-dashboard-widget/
I've hardcoded logic for sidebars, but I've also used WordPress › Widget Logic « WordPress Plugins for my own and client sites. It's easy to use with a simplified version of WP conditionals, like is_category and is_page ('101')
For someone else tackling this same problem -- there is a new plugin out that solves this problem very well. It even makes creating the sidebars easy. You can check it out here:
http://wordpress.org/extend/plugins/custom-sidebars/

Categories