Skip to content

Instantly share code, notes, and snippets.

@joeyz
joeyz / WP Loop with pagination
Last active August 29, 2015 14:07
Wordpress Pagination for archive page
//Dont forget to set how many items you want on each page in "Settings > Reading > Blog pages show at most"
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
// WP_Query arguments
$args = array (
'pagination' => true,
'paged' => $paged,
'order' => 'ASC'
);
@joeyz
joeyz / widgetarea
Created October 8, 2014 14:48
Add top widgeted area in a genesis theme
/** Register Topads widget area */
genesis_register_sidebar( array(
'id' => 'topads',
'name' => __( 'Hero Area', 'custom-theme' ),
'description' => __( 'Here you can place a hero ad or a slider', 'custom-theme' ),
) );
/** Add topads widget after the primary menu */
@joeyz
joeyz / admin-stylesheet
Created October 8, 2014 19:36
Add admin css sheet based on user ID(good for hiding admin menu)
// custom admin style sheet
function my_admin_head() {
$whodat = get_current_user_id();
if ($whodat == 2) {
echo '<link href="' .get_bloginfo('stylesheet_directory'). '/css/admin-menu.css" rel="stylesheet" type="text/css">';
}
}
add_action('admin_head', 'my_admin_head');
@joeyz
joeyz / cpt-search-results
Last active August 29, 2015 14:07
Search Results Page for a CPT
<?php
/*
Template Name: Events Search Page
*/
global $query_string;
$query_args = explode("&", $query_string);
//this is where you would normally put your $args array
$search_query = array();
@joeyz
joeyz / basic-widget
Created October 9, 2014 20:02
Basic Widget Code
<?php
/*
Plugin Name: Custom Mini Cart
Plugin URI: https://www.zendesignfitm.com/
Description: A widget framework for jewelry dropdown.
Version: 1.0
Author: Joey Z
Author URI: https://www.zendesignfirm.com/
License: GPL
*/
@joeyz
joeyz / wp-plugin-include
Created October 9, 2014 19:37
Proper way to include plugins in your WP theme
// This function loads the plugin.
function jz_load_plugin() {
if (!class_exists('Vintage_Engagement_Widget')) {
// load Vintage Engagement Widget if not already loaded
include_once(TEMPLATEPATH.'/plugins/vintage_engagement_widget.php');
}
if (!class_exists('Jewelry_Widget')) {
// load Vintage Engagement Widget if not already loaded
include_once(TEMPLATEPATH.'/plugins/jewelry_widget.php');
@joeyz
joeyz / cpt-search
Created October 9, 2014 16:02
Search form for Custom Post Types
@joeyz
joeyz / sticky-footer
Created October 10, 2014 14:57
jQuery responsive sticky footer
@joeyz
joeyz / num-per-row
Created October 13, 2014 18:14
WooCommerce Override number of products per row
//Goes in functions.php
// Change number or products per row to 3
add_filter('loop_shop_columns', 'loop_columns');
if (!function_exists('loop_columns')) {
function loop_columns() {
return 3; // 3 products per row
}
}
@joeyz
joeyz / gist:2f7964711786bee1ef09
Created October 13, 2014 19:14
WooCommerce Add header image with the categories thumnail
<div class="row">
<div class="archive-header">
<?php
//firs argument of the action is WHERE the function hooks into
add_action( 'woocommerce_before_main_content', 'woocommerce_category_image', 2 );
function woocommerce_category_image() {
if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );