Created
May 29, 2013 14:17
-
-
Save sonicpunk/5670598 to your computer and use it in GitHub Desktop.
MODX snippet. It checks if the resource has siblings and outputs two different classes onto an HTML element such as a div
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//[[haveSiblings? &classtwo=`no_sub_menu` &classone=`with_sub_menu`]] | |
<?php | |
if(!isset($modx)) return ''; | |
/* setup vars */ | |
$exclude = !empty($exclude) ? (is_array($exclude) ? $exclude : explode(',', str_replace(' ', '', $exclude))) : null; | |
$id = $modx->resource->get('id'); | |
if(!is_null($exclude) && in_array($id, $exclude)) return ''; | |
$output = ''; | |
$parents = $modx->getParentIds($id); | |
$parentCount = count($parents); | |
$parent = array_shift($parents); | |
$childCount = count($modx->getChildIds($id)); | |
/* get submenu */ | |
if($parentCount > 1 || $childCount > 0) | |
{ | |
if($parentCount > 1 && $childCount > 0) | |
{ | |
$output .= $classone; | |
} | |
elseif($parentCount > 1 && $childCount == 0) | |
{ | |
$output .= $classone; | |
} | |
elseif($parentCount == 1 && $childCount > 1) | |
{ | |
$output .= $classone; | |
} | |
} | |
else{ | |
$output .=$classtwo; | |
} | |
return $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment