Skip to content

Instantly share code, notes, and snippets.

@nutsandbolts
Last active August 29, 2015 14:15
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 nutsandbolts/2bda411c602078a92a19 to your computer and use it in GitHub Desktop.
Save nutsandbolts/2bda411c602078a92a19 to your computer and use it in GitHub Desktop.
Product View template
//* Move featured image above the title
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );
add_action( 'genesis_entry_header', 'genesis_do_post_image', 8 );
//* Modify the Genesis content limit read more link
add_filter( 'get_the_content_more_link', 'custom_read_more_link' );
function custom_read_more_link() {
return '... <p><a class="morelink" href="' . get_permalink() . '">View the Post</a></p>';
}
//* Load product template on blog and archives
add_filter( 'template_include', 'nabm_product_view_template' );
function nabm_product_view_template( $template ) {
if ( is_home() || is_archive() ) {
$template = get_query_template( 'product-view' );
}
return $template;
}
<?php
/**
* Creates a custom loop for the blog and archive pages.
*
* @package Genesis Sample
* @subpackage Genesis
* @copyright Copyright (c) 2015, Nuts and Bolts Media, LLC
* @license GPL-2.0+
* @since 2.0.0
*/
function nabm_has_product() {
if ( ! function_exists( 'get_field' ) ) {
return false;
}
$product = get_field( 'product_image' ) . get_field( 'product_link' );
if ( ! empty( $product ) ) {
return true;
}
return false;
}
add_action( 'genesis_entry_content', 'nabm_products_wrap_open', 9 );
function nabm_products_wrap_open() {
if ( ! nabm_has_product() ) {
return;
}
echo '<div class="home-products"><div class="one-half first product-excerpt">';
}
add_action( 'genesis_entry_content', 'nabm_products_content_wrap_close', 11 );
function nabm_products_content_wrap_close() {
if ( ! nabm_has_product() ) {
return;
}
echo '</div>';
}
add_action( 'genesis_entry_content', 'nabm_products_do_product_view', 12 );
function nabm_products_do_product_view() {
if ( ! nabm_has_product() ) {
return;
}
$product_link = get_field( 'product_link' );
$product_image = get_field( 'product_image' );
echo '<div class="one-half product-view">';
if ( ! empty( $product_link ) && ! empty( $product_image ) ) {
echo '<a href="' . esc_url( $product_link ) .'" target="_blank"><img class="product-image aligncenter" src="' . esc_url( $product_image ) .'"></a>';
}
if ( ! empty( $product_link ) ) {
echo '<p><a href="' . esc_url( $product_link ) .'" class="product-link" target="_blank">Get the Details</a></p>';
}
echo '</div>';
}
add_action( 'genesis_entry_content', 'nabm_products_wrap_close', 13 );
function nabm_products_wrap_close() {
if ( ! nabm_has_product() ) {
return;
}
echo '</div>';
}
// Fix priorities for elements after the main content.
remove_action( 'genesis_entry_content', 'genesis_do_post_content_nav', 12 );
add_action( 'genesis_entry_content', 'genesis_do_post_content_nav', 14 );
remove_action( 'genesis_entry_content', 'genesis_do_post_permalink', 14 );
add_action( 'genesis_entry_content', 'genesis_do_post_permalink', 15 );
genesis();
/* ## Home Product View
--------------------------------------------- */
.home-products {
clear: both;
display: flex;
display: inline-flex; /* fallback for Firefox */
}
.product-excerpt {
align-self: flex-end;
}
.product-view {
text-align: center;
align-self: flex-end;
}
@media only screen and (max-width: 650px) {
.home-products {
display: inline-block;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment