Joomla 3 transfer parent title variable of active menu item - php

Thanks to all of you I have been able to create a variable: $mytitle from the active parent menu item in Joomla 3.
This is my code:
$menu = JFactory::getApplication()->getMenu();
$parent = $menu->getItem( $menu->getActive()->parent_id );
$parentname = $parent->title;
$parentlink = JRoute::_( $parent->link . '&Itemid=' . $parent->id );
$menulevel = $menu->getActive()->level; $activename= $menu->getActive()->title;
$mytitle = ($menulevel == 1)?$activename:$parentname;
echo $mytitle;
This works great but now I need to use it on my submenu item (VMenuBlock). The code is as follows and I cannot seem to figure out how to place the variable so that it works?
function modChrome_vmenu($module, &$params, &$attribs)
{
if (!empty ($module->content)) {
if (function_exists('VMenuBlock'))
echo VMenuBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
else
echo Block(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
}
}
Any help is appreciated!,
Thanks!
Doug

Related

Php Code showing Following error in the webpage

am using joomla .. ,
by runnig the joomla it showing the following error in the link part
and the main error is about the parameter is expecting to a reference.
if i change it , it will not show any links
Warning: Parameter 2 to modChrome_artblock() expected to be a
reference, value given in
D:\xampp\htdocs\Site\templates\a_2\html\modules.php on
line 36
Warning: Parameter 3 to modChrome_artblock() expected to be a
reference, value given in
D:\xampp\htdocs\site\templates\a_2\html\modules.php on
line 36
and the php code on this error is
- <?php
defined('_JEXEC') or die;
if (!defined('_ARTX_FUNCTIONS'))
require_once dirname(__FILE__) . str_replace('/', DIRECTORY_SEPARATOR, '/../functions.php');
function modChrome_artstyle($module, &$params, &$attribs)
{
$style = isset($attribs['artstyle']) ? $attribs['artstyle'] : 'art-nostyle';
$styles = array(
'art-nostyle' => 'modChrome_artnostyle',
'art-block' => 'modChrome_artblock',
'art-article' => 'modChrome_artarticle',
'art-vmenu' => 'modChrome_artvmenu'
);
// moduleclass_sfx support:
// '' or 'suffix' - the default module style: custom suffix will not be added to the module tag
// but will be added to the module elements.
// ' suffix' - adds suffix to the module as well as to the module elements.
// 'art-...' - overwrites the default module style.
// 'suffix art-...' - overwrites the default style and adds suffix to the module and
// to its elements, does not add art-... to the module elements.
$classes = explode(' ', rtrim($params->get('moduleclass_sfx')));
$keys = array_keys($styles);
$art = array();
foreach ($classes as $key => $class) {
if (in_array($class, $keys)) {
$art[] = $class;
$classes[$key] = ' ';
}
}
$classes = str_replace(' ', ' ', rtrim(implode(' ', $classes)));
$style = count($art) ? array_pop($art) : $style;
$params->set('moduleclass_sfx', $classes);
> call_user_func($styles[$style], $module, $params, $attribs);
}
function modChrome_artnostyle($module, &$params, &$attribs)
{
if (!empty ($module->content)) : ?>
<!-- begin nostyle -->
<div class="art-nostyle<?php echo $params->get('moduleclass_sfx'); ?>">
<?php if ($module->showtitle != 0) : ?>
<h3><?php echo $module->title; ?></h3>
<?php endif; ?>
<!-- begin nostyle content -->
<?php echo $module->content; ?>
<!-- end nostyle content -->
</div>
<!-- end nostyle -->
<?php endif;
}
function modChrome_artblock($module, &$params, &$attribs)
{
if (!empty ($module->content))
echo artxBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
}
function modChrome_artvmenu($module, &$params, &$attribs)
{
if (!empty ($module->content)) {
if (function_exists('artxVMenuBlock'))
echo artxVMenuBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
else
echo artxBlock(($module->showtitle != 0) ? $module->title : '', $module->content,
$params->get('moduleclass_sfx'));
}
}
function modChrome_artarticle($module, &$params, &$attribs)
{
if (!empty ($module->content)) {
$data = array('classes' => $params->get('moduleclass_sfx'), 'content' => $module->content);
if ($module->showtitle != 0)
$data['header-text'] = $module->title;
echo artxPost($data);
}
}
it showing the error
call_user_func($styles[$style], $module, $params, $attribs);
try the following, it will solve your problem
Go to Module -> Advance -> Module Style -> Change "inherited" to corresponding position styles. (e.g: select art-nostyle, art-block et)
in that case you don't have to scale down Php version
*****it should open in joomla administrator, then do the above steps
You can use
function modChrome_artblock($module, $params, $attribs)
instead of
function modChrome_artblock($module, &$params, &$attribs)

WordPress sidebar navigation based off of top-level parent page

I'm trying to create a complex sidebar navigation system that remains the same depending on what top-level page you're viewing. For example, say I have this navigation:
Home
About
Our Company
Location
Hours
Our PeopleJim
Dave
Sarah
Kelly
PortfolioLogos
Websites
Contact
Now, if the user was anywhere within the About section, I'd want the sidebar to display:
About
Our Company
Location
Hours
Our PeopleJim
Dave
Sarah
Kelly
That goes for if they're in the main About page, in the Our Company page, or in the Location page. I need the whole navigation visible regardless of depth.
If the user was in a page with no sub-items, such as Contact, the sidebar needs to show:
Home
About
Portfolio
Contact
What's more, the ordering needs to be based on a WordPress Menu (one main menu, each sidebar can't be it's own; that's too complicated for the user). I don't know if that complicates things or not.
In the past, I've managed to get something to display children and sibling pages, but it doesn't display parent pages, and doesn't display in the order that the user defines.
<ul>
<?
global $wp_query;
if( empty($wp_query->post->post_parent) ) {
$parent = $wp_query->post->ID;
}
else {
$parent = $wp_query->post->post_parent;
}
wp_list_pages ("&title_li=&child_of=$parent");
?>
</ul>
If this can be modified to work the way I want it, that'd be great. I'm going to try and figure this out on my own, and will post updates as I make progress.
UPDATE 1: I've made a bit of progress determining what the absolute parent is. I think I'm on the right track.
<?
if ($post->post_parent) {
$ancestors = get_post_ancestors($post->ID);
$root = count($ancestors)-1;
$parent = $ancestors[$root];
} else {
$parent = $post->ID;
}
echo "Current Page: " . $post->ID . "<br />";
echo "Top Level Parent: " . $parent;
?>
UPDATE 2: I can now determine the correct page ID to query for a menu, so I think I'm getting close.
<?
$children = get_pages("child_of=".$post->ID);
if ($post->post_parent) {
$ancestors = get_post_ancestors($post->ID);
$root = count($ancestors)-1;
$parent = $ancestors[$root];
} elseif (count($children) != 0) {
$parent = $post->ID;
} else {
$parent = 0;
}
echo "Current Page: " . $post->ID . "<br />";
echo "Top Level Parent: " . $parent;
?>
UPDATE 3: I'm nearly there! The only problem is this uses the page's order from the editor, not from the menu. Is it possible to edit this to work with a menu instead?
<aside>
<?
$children = get_pages("child_of=".$post->ID);
if ($post->post_parent) {
$ancestors = get_post_ancestors($post->ID);
$root = count($ancestors)-1;
$parent = $ancestors[$root];
$sidebarDepth = 0;
$postParentID = get_post($parent);
$title = $postParentID->post_title;
} elseif (count($children) != 0) {
$parent = $post->ID;
$sidebarDepth = 0;
$postParentID = get_post($parent);
$title = $postParentID->post_title;
} else {
$parent = 0;
$sidebarDepth = 1;
$frontPageID = get_option("page_on_front");
$exclude = $frontPageID;
$postParentID = get_post($frontPageID);
$title = $postParentID->post_title;
}
?>
<header>
<h6><? echo $title ?> »</h6>
</header>
<section>
<nav>
<?
echo "<ul>";
wp_list_pages("child_of=" . $parent . "&depth=" . $sidebarDepth . "&exclude=" . $exclude . "&title_li=&");
echo "</ul>";
?>
</nav>
</section>
</aside>
Figured it out! I modified the code from this answer to add a start_in option to wp_nav_menu, and modified my code from there. Now this works exactly as I wanted it.
In functions.php:
// add start_in argument to navigation
add_filter("wp_nav_menu_objects",'my_wp_nav_menu_objects_start_in',10,2);
function my_wp_nav_menu_objects_start_in( $sorted_menu_items, $args ) {
if (isset($args->start_in) && $args->start_in != 0) {
$menu_item_parents = array();
foreach ($sorted_menu_items as $key => $item) {
if ($item->object_id == (int)$args->start_in) $menu_item_parents[] = $item->ID;
if (in_array($item->menu_item_parent, $menu_item_parents)) {
$menu_item_parents[] = $item->ID;
} else {
unset($sorted_menu_items[$key]);
}
}
return $sorted_menu_items;
} else {
return $sorted_menu_items;
}
}
In page.php (or whatever template you want):
<aside>
<?
if ($post->post_parent) {
$ancestors = get_post_ancestors($post->ID);
$root = count($ancestors)-1;
$parent = $ancestors[$root];
} elseif (count(get_pages("child_of=".$post->ID)) != 0) {
$parent = $post->ID;
} else {
$parent = get_option("page_on_front");
$sidebarDepth = 1;
$exclude = $parent;
}
if ($post->post_parent || count(get_pages("child_of=".$post->ID)) != 0) {
$sidebarDepth = 0;
$start_in = $parent;
$depth = 0;
} else {
$depth = 1;
$start_in = 0;
}
$parentID = get_post($parent);
$parentTitle = $parentID->post_title;
$parentURL = get_permalink($parentID);
?>
<header>
<h6><? echo $parentTitle ?> »</h6>
</header>
<section>
<nav>
<?
wp_nav_menu(
array(
"container" => false,
"depth" => $depth,
"items_wrap" => '<ul>%3$s</ul>',
"start_in" => $start_in,
"theme_location" => "first"
)
);
?>
</nav>
</section>
</aside>

Can't get slash to appear correctly

I'm not sure where I'm going wrong, but I'm trying to make the slash only appear on the first drop down level of a menu. I'm doing this in php.
Here is my code
function appendMainNav($subid){
global $_PAGES_TABLE, $_HTTP_ADDRESS;
$subWrapper='';
$subClass='';
$mainClass='mega-nav-wrapper overlay-bg';
if($this->hasParentMenu($subid) > 0){
$subWrapper = 'sub-nav-main-wrapper';
$subClass='sub-nav-wrapper';
$mainClass='';
}
$p=1;
$str = "";
$str.= '<div class="'.$subWrapper.'">';
$str.=' <ul class="'.$mainClass.''.$subClass.'">';
$query = mysql_query("SELECT * FROM $_PAGES_TABLE P WHERE P.parent='".$subid."' AND P.show='1' AND P.active='1' ORDER BY num");
while( $result = mysql_fetch_object($query) ){
$page = new Page($result->id);
$page->setFromDatabase();
$lastClass='';
if(($page->linkto != '0' && $page->linkto != 0 && $page->linkto != '') || $page->linkto == '#'){
$linkto = $page->linkto;
}else{
$linkto = $page->id;
}
$appendArrow='';
$arrowSelect = "";
$slash =' ';
if($this->hasChildrenMenu($page->id) > 0){
$slash = ' /';
}
$str .='<li class="subnav_item'.$lastClass.'"><a class="'.$appendArrow.'" href="'.getSEOLink($linkto).'">'.$page->{'title'.$langVar}.''.$slash.'</a>';
//$str.='<li><span>/</span></li>';
if($this->hasChildrenMenu($page->id) > 0){
$str.= $this->appendMainNav($page->id);
}
$str.='</li>';
$p++;
}
$str.=' </ul>';
$str.='</div>';
return $str;
At the moment it only appears on the sub menu item that has a drop drop down as well. The second drop down mustn't have anything.
My menu looks like this
menu 1 menu 2 / menu 3
submenu 1
submenu 2
submenu 3
and this is how I want it to look
menu 1 / menu 2 / menu 3 /
submenu 1
submenu 2
submenu 3
An easy solution would be to add a flag to the function and change the conditional:
function appendMainNav($subid, $noSlash = false){
...
if(!$noSlash){
$slash = ' /';
}
...
if($this->hasChildrenMenu($page->id) > 0){
$str.= $this->appendMainNav($page->id, true);
}
...

Hide language WPML

I am using WPML language, and cant find solution for next thing:
On the Language switcher i want to hide language, lets say for example - "he", if current language is lets say for example "ar", so when we on arabic site we will not see on the selector the Hebrew, and same thing if we on Hebrew, the arabic will not display.
On shorten words: what i want is - if we on arabic site - the hebrew flag will be hidden.
What i tried:
function language_selector_flags(){
$languages = icl_get_languages('skip_missing=0');
if(!empty($languages)){
if(ICL_LANGUAGE_CODE=='en')
{
$order = array('ar'); //Specify your sort order here
}
elseif(ICL_LANGUAGE_CODE=='he')
{
$order = array('en', 'ar'); //Specify your sort order here
}
foreach ($order as $l) {
if (isset($languages[$l])) {
$l = $languages[$l]; //grab this language from the unsorted array that is returned by icl_get_languages()
//Display whatever way you want -- I'm just displaying flags in anchors (CSS: a {float:left; display:block;width:18px;height:12px;margin:0 2px;overflow:hidden;line-height:100px;})
if($l['active']) { $class = "active"; $url=""; } else { $class = ''; $url = 'href="'.$l['url'].'"'; }
echo '<a '.$url.' style="background:url('.$l['country_flag_url'].') no-repeat;" class="flag '.$class.'">';
echo $l['language_code'].'';
}
}
}
}
Its not affect at all the selector.
You can check out the plugin WPML Flag In Menu.
You could use the plugin_wpml_flag_in_menu() function from the plugin (see source code here) and replace:
// Exclude current viewing language
if( $l['language_code'] != ICL_LANGUAGE_CODE )
{
// ...
}
with
// Include only the current language
if( $l['language_code'] == ICL_LANGUAGE_CODE )
{
// ...
}
to show only the current language/flag, if I understand you correctly.
ps: If you need further assistance, you could for exampe show us the output of this debug function for the active language:
function debug_icl_active_language()
{
$languages = icl_get_languages( 'skip_missing=0' );
foreach( (array) $languages as $l )
{
if( $l['active'] )
{
printf( '<pre> Total languages: %d - Active: %s </pre>',
count( $languages ),
print_r( $l, TRUE ) );
}
}
}
i have some useful link for you, please go through it first:
http://wpml.org/forums/topic/hide-language-vs-display-hidden-languages-in-your-profile-not-working/
http://wpml.org/forums/topic/hide-one-language/
http://wpml.org/forums/topic/hiding-active-language-in-menu/
http://wpml.org/forums/topic/language-selector-how-to-hide-one-language/
thanks
function language_selector_flags(){
$languages = icl_get_languages('skip_missing=0');
if(!empty($languages)){
$filter = array();
$filter['ar'] = array( 'he' );
// set your other filters here
$active_language = null;
foreach ($languages as $l)
if($l['active']) {
$active_language = $l['language_code'];
break;
}
$filter = $active_language && isset( $filter[$active_language] ) ? $filter[$active_language] : array();
foreach ($languages as $l) {
//Display whatever way you want -- I'm just displaying flags in anchors (CSS: a {float:left; display:block;width:18px;height:12px;margin:0 2px;overflow:hidden;line-height:100px;})
if( in_array( $l['language_code'], $filter) )
continue;
if($l['active']) { $class = "active"; $url=""; } else { $class = ''; $url = 'href="'.$l['url'].'"'; }
echo '<a '.$url.' class="flag '.$class.'"><img src="', $l['country_flag_url'], '" alt="', esc_attr( $l['language_code'] ), '" /></a>';
}
}
}
EDIT: If I get this right, your client(I assume) doesn't want his customers (Israelis especiay) to know that he offer service also to the arabic speaking cusomers. If it so then you can parse the Accept-Language header and filter the language selector according the result.
I have a similar problem/issue:
On this website: https://neu.member-diving.com/
I have languages I not need in the switcher. I tried the code above, but it nothing changed so far.
So, what I would like to do is, When a client is on the one "german" page, the other german languages in the switcher should not need to be there, only the english one and the actual german one.
Where do I need to put code like
function language_selector_flags(){
$languages = icl_get_languages('skip_missing=0');
if(!empty($languages)){
$filter = array();
$filter['ar'] = array( 'he' );
// set your other filters here
$active_language = null;
foreach ($languages as $l)
if($l['active']) {
$active_language = $l['language_code'];
break;
}
$filter = $active_language && isset( $filter[$active_language] ) ? $filter[$active_language] : array();
foreach ($languages as $l) {
//Display whatever way you want -- I'm just displaying flags in anchors (CSS: a {float:left; display:block;width:18px;height:12px;margin:0 2px;overflow:hidden;line-height:100px;})
if( in_array( $l['language_code'], $filter) )
continue;
if($l['active']) { $class = "active"; $url=""; } else { $class = ''; $url = 'href="'.$l['url'].'"'; }
echo '<a '.$url.' class="flag '.$class.'"><img src="', $l['country_flag_url'], '" alt="', esc_attr( $l['language_code'] ), '" /></a>';
}
}
}

Add active class to current subcategory

With the code blow I retrieve the current parent category and his children. Is it possible to add an active class for the current child?
<?php
$currentCat = Mage::registry('current_category');
if ( $currentCat->getParentId() == Mage::app()->getStore()->getRootCategoryId() )
{
$loadCategory = $currentCat;
}
else
{
$loadCategory = Mage::getModel('catalog/category')->load($currentCat->getParentId());
}
$subCategories = explode(',', $loadCategory->getChildren());
foreach ( $subCategories as $subCategoryId )
{
$cat = Mage::getModel('catalog/category')->load($subCategoryId);
if($cat->getIsActive())
{
echo '<li>'.$cat->getName().'</li>';
}
}
?>
You already have the current category, so you can check it's ID against the IDs of the categories being looped through.
Where you have
echo '<li>'.$cat->getName().'</li>';
Change it to do the check for the ID and then add the "active" class when found
$class = '';
if ($currentCat->getId() == $cat->getId())
{
$class = ' class="active"';
}
echo '<li'.$class.'>'.$cat->getName().'</li>';
To set the category as active we have to set the current category in catalog layer.
$_categoryName=YourCategoryName;
$_category = Mage::getModel('catalog/category')->loadByAttribute('name', $_categoryName);
Mage::getSingleton('catalog/layer')->setCurrentCategory($_category);
This looks better than ugly hack of changing in phtml filter..

Categories