Skip to content

Instantly share code, notes, and snippets.

@wpperform
Last active December 17, 2015 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpperform/5573854 to your computer and use it in GitHub Desktop.
Save wpperform/5573854 to your computer and use it in GitHub Desktop.
Page template for Themedy Clip Cart theme where products are sorted by title in ascending order
<?php
/**
* Template Name: Products Sorted By Name
*
* Page template for Themedy Clip Cart theme tweaked by wpPERFORM
* Displays product archive in ascending name (title) order
*
* Note: The custom template can't be changed on a page with a slug of 'products'
*/
// Add .product-page class to content
add_filter('post_class', 'product_post_class');
function product_post_class( $classes ) {
$classes[] = 'product-page';
return $classes;
}
// New Sidebars
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
remove_action( 'genesis_sidebar_alt', 'genesis_do_sidebar_alt' );
add_action( 'genesis_sidebar', 'themedy_do_product_sidebar' );
function themedy_do_product_sidebar() {
if ( !dynamic_sidebar('primary-product-sidebar') ) {
echo '<div class="widget widget_text"><div class="widget-wrap">';
echo '<h4 class="widgettitle">';
_e('Primary Product Sidebar', 'themedy');
echo '</h4>';
echo '<div class="textwidget"><p>';
printf(__('This is the Primary Product Sidebar. You can add content to this area by visiting your <a href="%s">Widgets Panel</a> and adding new widgets to this area.', 'genesis'), admin_url('widgets.php'));
echo '</p></div>';
echo '</div></div>';
}
}
add_action( 'genesis_sidebar_alt', 'themedy_do_product_sidebar_alt' );
function themedy_do_product_sidebar_alt() {
if ( !dynamic_sidebar('secondary-product-sidebar') ) {
echo '<div class="widget widget_text"><div class="widget-wrap">';
echo '<h4 class="widgettitle">';
_e('Secondary Product Sidebar', 'themedy');
echo '</h4>';
echo '<div class="textwidget"><p>';
printf(__('This is the Secondary Product Sidebar. You can add content to this area by visiting your <a href="%s">Widgets Panel</a> and adding new widgets to this area.', 'genesis'), admin_url('widgets.php'));
echo '</p></div>';
echo '</div></div>';
}
}
add_action('genesis_after_loop', 'themedy_do_product_loop');
function themedy_do_product_loop() { ?>
<ul class="product_list">
<?php
global $wp_query, $post;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$tax = $wp_query->query_vars[PRODUCTS_CATEGORY_NAME];
query_posts( array ('posts_per_page' => themedy_get_option('product_limit'), 'orderby' => 'title', 'order' => 'ASC', 'post_type' => PRODUCTS_NAME, 'paged' => $paged, PRODUCTS_CATEGORY_NAME => $tax ) );
$loop_counter = 1;
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<li class="product <?php if ( $loop_counter == 3 ) { echo "product-last"; } ?>">
<div class="product_wrap">
<?php
$title = get_the_title().' ';
$chars_title = strlen($title);
$title = substr($title,0,28);
$title = substr($title,0,strrpos($title,' '));
if ($chars_title > 28) { $title = $title."..."; }
$excerpt = get_the_excerpt();
if (strlen($excerpt) > 150) {
$excerpt = substr($excerpt,0,strpos($excerpt,' ',80)); } ;
$excerpt = $excerpt.' ...';
if (genesis_get_image()) {
$img = genesis_get_image( array( 'format' => 'html', 'size' => 'Product Thumb', 'attr' => array( 'title' => $post_title ) ) );
printf( '<a href="%s" class="product-thumb" title="%s">%s</a>', get_permalink(), the_title_attribute('echo=0'), $img );
}
?>
<h3 class="entry-title product-title"><a href="<?php the_permalink(); ?>" class="title"><?php echo $title; ?></a></h3>
<div class="product_content">
<?php echo apply_filters('the_excerpt',$excerpt); ?>
</div>
<div class="product_details">
<a class="button" href="<?php the_permalink(); ?>">More Info</a>
<div class="price"><?php echo themedy_get_currency_sign(); echo themedy_get_price(); ?></div>
</div>
</div>
</li>
<?php if ( $loop_counter == 3 ) {
$loop_counter = 1;
echo '<li class="clear"></li>';
} else {
$loop_counter++;
} ?>
<?php endwhile; else: endif; ?>
</ul>
<?php
genesis_posts_nav(); // Navigation
wp_reset_query(); // Reset Query
?>
<?php }
// Remove standard loop
remove_action('genesis_loop', 'genesis_do_loop');
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment