Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tylerforesthauser/7177720 to your computer and use it in GitHub Desktop.
Save tylerforesthauser/7177720 to your computer and use it in GitHub Desktop.
Used to display current category's immediate parent on Product Listing pages.
<?php
$strC = Yii::app()->getRequest()->getQuery('cat');
$objCategory = Category::LoadByRequestUrl($strC);
?>
<?= ($objCategory->Parent) ? '<h2>'.$objCategory->Parent->label.'</h2>' : '' ?>
@tylerforesthauser
Copy link
Author

For use in the /search/grid.php view.

@admcfajn
Copy link

I've used the following in views/site/main.php

Which would be quicker: querying the database for the category-parent or detecting the category-parent in the slug?

elseif (strpos($catSlug,'outdoor') !== false) {
  echo '<div id="outdoor-header"><h1 class="category-heading">' .  $this->pageHeader . '</h1></div>';
  echo '<div class="sub-menu-container container">';
  echo wp_nav_menu( array( 'theme_location' => 'ooutdoor_nav', 'menu_class' => 'sub-category-nav visible-desktop' ) );
  echo '</div>';    
} else { 
  echo '<div id="default-header" class="pageheader"><h1 class="category-heading">' . $this->pageHeader . '</h1></div>';
  echo '<div class="sub-menu-container container">';
  echo wp_nav_menu( array( 'theme_location' => 'living_room_nav', 'menu_class' => 'sub-category-nav visible-desktop' ) );
  echo '</div>';
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment