Skip to content

Instantly share code, notes, and snippets.

@JPry
Created January 6, 2012 04:13
Show Gist options
  • Save JPry/1568927 to your computer and use it in GitHub Desktop.
Save JPry/1568927 to your computer and use it in GitHub Desktop.
Files used to add town specific category archives and styling
<?php
// First, get the current query object so we can work with it
$current_query = get_queried_object();
// Run only if the parent category is "Towns" and the sidebars are active for that town
if ( get_cat_ID( 'Towns' ) == $current_query->category_parent ) {
add_filter( 'does_city_style', 'does_site_town_name' );
if ( is_active_sidebar( $current_query->slug . '-featured-top' ) || is_active_sidebar( $current_query->slug . '-bottom-left' ) || is_active_sidebar( $current_query->slug . '-bottom-right' ) ) {
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'does_category_featured_top' );
add_action( 'genesis_loop', 'does_category_featured_bottom' );
}
}
?>
<?php
function does_category_featured_top() {
$current_query = get_queried_object();
?>
<div id="featured-top">
<?php if ( ! dynamic_sidebar( $current_query->cat_name . ' Featured Top' ) ) : ?>
<div class="widget">
<h4><?php echo $current_query->cat_name . ' Featured Top'; ?></h4>
<div class="wrap">
<p>This is a widgeted area which is called <?php echo $current_query->cat_name; ?> Featured Top.</p>
</div><!-- end .wrap -->
</div><!-- end .widget -->
<?php endif; ?>
</div><!-- end #featured-top -->
<?php
}
function does_category_featured_bottom() {
$current_query = get_queried_object();
?>
<div id="featured-bottom">
<div class="featured-bottom-left">
<?php if ( ! dynamic_sidebar( $current_query->cat_name . ' Bottom Left' ) ) : ?>
<!-- Empty widget area -->
<?php endif; ?>
</div><!-- end .featured-bottom-left -->
<div class="featured-bottom-right">
<?php if ( ! dynamic_sidebar( $current_query->cat_name . ' Bottom Right' ) ) : ?>
<!-- Empty widget area -->
<?php endif; ?>
</div><!-- end .featured-bottom-right -->
</div><!-- end #featured-bottom -->
<?php
}
?>
<?php
genesis();
?>
<?php
function does_site_town_name( $town ) {
$current_query = get_queried_object();
$town = $current_query->slug;
return $town;
}
?>
<?php
function get_city_style_color( $city ) {
switch ( $city ):
case 'coatesville':
return '#B61023';
case 'downingtown':
return '#0690a5';
case 'exton':
return '#92BD68';
case 'west_chester':
case 'west-chester':
return '#447EBA';
case 'pet':
return '#c36417';
/** Downingtown-related styles */
case 'east-brandywine':
return '#00A599';
case 'east-caln':
return '#005159';
case 'west-bradford':
return '#002D36';
/** Exton-related styles */
case 'west-whiteland':
return '#73AF55';
case 'west-pikeland':
return '#275E37';
case 'upper-uwchlan':
return '#34B233';
case 'uwchlan':
return '#009B48';
/** Coatesville-related styles */
case 'caln':
return '#F18B7D';
case 'east-fallowfield':
return '#F54359';
case 'sadsbury':
return '#500409';
case 'valley':
return '#D80A19';
case 'west-brandywine':
return '#F62C3A';
default:
return '#000';
endswitch;
}
?>
<?php
function get_does_town_categories( $args = array() ) {
// Stop immediately if the "Towns" category doesn't exist, and return empty array
if ( 0 == get_cat_ID( 'Towns' ) )
return array();
$defaults = array(
'parent' => get_cat_ID( 'Towns' ),
'order' => 'ASC',
'hide_empty' => 0,
);
$args = wp_parse_args( $args, $defaults );
return get_categories( $args );
}
?>
<?php
$town_categories = get_does_town_categories();
?>
<?php
foreach ( $town_categories as $category ) {
$featured_category = get_does_town_categories( array( 'parent' => $category->cat_ID ) );
if ( is_object( $featured_category[0] ) ) {
$featured_ID = $featured_category[0]->cat_ID;
} else {
$featured_ID = 'NOT DEFINED. Please go to Posts > Categories to create a "Featured" category under ' . $category->cat_name;
}
genesis_register_sidebar( array(
'name' => $category->cat_name . ' Featured Top',
'id' => $category->slug . '-featured-top',
'description' => 'This is the featured section of the ' . $category->cat_name . ' page.',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>'
) );
genesis_register_sidebar( array(
'name' => $category->cat_name . ' Bottom Left',
'id' => $category->slug . '-bottom-left',
'description' => 'This is the bottom left section of the ' . $category->cat_name . ' page. The featured ID to exclude is ' . $featured_ID . '.',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>'
) );
genesis_register_sidebar( array(
'name' => $category->cat_name . ' Bottom Right',
'id' => $category->slug . '-bottom-right',
'description' => 'This is the bottom right section of the ' . $category->cat_name . ' page. The featured ID to exclude is ' . $featured_ID . '.',
'before_title' => '<h4 class="widgettitle">',
'after_title' => '</h4>'
) );
}
?>
<?php
add_action( 'wp_head', 'does_site_city_theme' );
function does_site_city_theme() {
if ( ! is_admin() ) {
$city = apply_filters( 'does_city_style', strtolower( genesis_get_does_site_option( 'city_style' ) ) );
$city_color = get_city_style_color( $city );
echo '
<style type="text/css">
a,
a:visited,
a:hover,
#content h2,
#content h2 a,
#content h2 a:visited,
#content #featured-top h2 a:hover,
#content #featured-bottom h2 a:hover,
#content h2 a:hover,
#sidebar a:hover,
#sidebar-alt a:hover,
#sidebar h2,
#sidebar h2 a,
#sidebar-alt h2,
#sidebar-alt h2 a,
#sidebar h2 a:hover,
#sidebar-alt h2 a:hover,
#cat{
color: ' . $city_color . ';
}
.ui-tabs .more-link-:hover {
background: ' . $city_color . ';
}
a.read-more-link:hover {
background: ' . $city_color . ' url(' . CHILD_URL . '/city_styles/' . $city . '/readmore-hover.png) left top repeat-x;
border: 1px solid ' . $city_color . ';
}
.navigation li a:hover, .navigation li.active a {
background: ' . $city_color . ';
border: 1px solid ' . $city_color . ';
}
.navigation li.disabled {
border: 1px solid ' . $city_color . ';
}
#submit:hover, .searchsubmit:hover, .enews #subbutton:hover, .gform_footer .button:hover {
background: ' . $city_color . ' !important;
border: 1px solid ' . $city_color . ';
}
#nav li a:hover,
#nav li li a:hover,
#nav li li a:active,
#nav .seasonal-page {
background: url(' . CHILD_URL . '/city_styles/' . $city . '/nav-hover.png) left top repeat-x;
}
</style>
';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment