Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mclanecreative/c3043476d342113aa5b2 to your computer and use it in GitHub Desktop.
Save mclanecreative/c3043476d342113aa5b2 to your computer and use it in GitHub Desktop.
Add Sticky Post to WooTheme's Storefront theme homepage
Note: Make sure you've created a Storefront Child Theme before attempting this. (https://codex.wordpress.org/Child_Themes) See this customization live here: https://theyouthcartel.com
Changelog
*0.1*
- Hell yeah, got it to work
- Adds sticky post to homepage template
- If no sticky post is selected, displays the latest post
Title: Add Sticky Post to Storefront Home
Description: While WooTheme's Storefront theme is great, the sole focus on product on the homepage doesn't work for every site. This customization allows Storefront users to add a sticky post to the bottom of the homepage.
Objective: Add a sticky post to the homepage of the Storefront theme.
Goal: I'd really like to contribute this an extension for the WordPress repository. This is very much a first attempt, it works, but it's got some deficiencies.
/**
* Change the excerpt length from 55 to whatever you want, add to your child theme's functions.php file
*/
function custom_excerpt_length( $length ) {
return 100;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
/* Add this to your child theme's style.css */
span#homeblogcontent {text-decoration:none !important;}
span#homeblogimage {float:right;padding: 4px; margin: 0 10px 2px 0;}
<?php
/**
* Customization by McLane Creative - Adding this file to your child theme's root folder will add the newest sticky post to your site's homepage. If no sticky post exists this will display the newest blog post.
*
* The template for displaying the homepage.
*
* This page template will display any functions hooked into the `homepage` action.
* By default this includes a variety of product displays and the page content itself. To change the order or toggle these components
* use the Homepage Control plugin.
* https://wordpress.org/plugins/homepage-control/
*
* Template name: Homepage
*
* @package storefront
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
/**
* @hooked storefront_homepage_content - 10
* @hooked storefront_product_categories - 20
* @hooked storefront_recent_products - 30
* @hooked storefront_featured_products - 40
* @hooked storefront_popular_products - 50
* @hooked storefront_on_sale_products - 60
* @hooked storefront_homeblog_content - 70
*/
do_action( 'homepage' ); ?>
<div id="homeblog">
<h2 class="section-title" align="center">On The Blog</h2>
<?php
$excerpts = new WP_Query( array(
'posts_per_page' => 1,
'post__in' => $sticky,
'ignore_sticky_posts' => 1
) );
if ( $excerpts->have_posts() ) :
?>
<?php
while ( $excerpts->have_posts() ) : $excerpts->the_post();
?>
<h1><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php the_title(); ?></a></h1>
<span id="homeblogimage"><?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail('thumbnail'); ?>
</a></span><span id="homeblogcontent"><?php endif; ?><?php the_excerpt(); ?></span><a href="<?php echo get_permalink(); ?>" class="button"> Read More...</a><?php
endwhile;
wp_reset_postdata();
?><?php
endif;
?></div>
</main><!-- #main -->
</div><!-- #primary -->
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment