Skip to content

Instantly share code, notes, and snippets.

View hemusyl's full-sized avatar

Humayun Kabir hemusyl

View GitHub Profile
@hemusyl
hemusyl / odd-even-postclass.php
Created May 16, 2017 11:12 — forked from neilgee/odd-even-postclass.php
Odd/Even Post Class in WordPress
<?php //<~ dont add me in
add_filter( 'post_class', 'themeprefix_odd_even_classes' );
function themeprefix_odd_even_classes( $classes ) {
global $wp_query;
if($wp_query->current_post % 2 == 0) {//http://stackoverflow.com/questions/7959247/php-test-if-number-is-odd-or-even
$classes[] = 'odd';
}
@hemusyl
hemusyl / even_odd_classes.php
Created May 15, 2017 09:10 — forked from gregrickaby/even_odd_classes.php
Even odd classes in WordPress loop
<?php
// WP_Query Arguments
$args = array(
'order' => 'DESC',
'posts_per_page' => 5
);
// The Loop
$query = new WP_Query( $args );
@hemusyl
hemusyl / single-page-walker.php
Created May 15, 2017 03:23 — forked from ninnypants/single-page-walker.php
Nav walker for single page WordPress sites
<?php
class Single_Page_Walker extends Walker_Nav_Menu{
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$classes[] = 'menu-item-' . $item->ID;
@hemusyl
hemusyl / example-functions.php
Created April 20, 2017 15:03
CMB2/example-functions.php
<?php
/**
* Include and setup custom metaboxes and fields. (make sure you copy this file to outside the CMB2 directory)
*
* Be sure to replace all instances of 'yourprefix_' with your project's prefix.
* http://nacin.com/2010/05/11/in-wordpress-prefix-everything/
*
* @category YourThemeOrPlugin
* @package Demo_CMB2
* @license http://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
@hemusyl
hemusyl / Wordpress featured images expanded
Created April 13, 2017 16:03 — forked from austinginder/Wordpress featured images expanded
Wordpress adding multiple featured images per post
@hemusyl
hemusyl / hk-meta-boxes.php
Created March 12, 2017 07:58
meta box ( Meta box of Option Tree plugin )
<?php
/**
* Initialize the custom Meta Boxes.
*/
add_action( 'admin_init', 'custom_meta_boxes' );
/**
* Meta Boxes demo code.
*
* You can find all the available option types in demo-theme-options.php.
@hemusyl
hemusyl / index.php
Created March 12, 2017 06:30 — forked from jameskoster/index.php
WooCommerce - Sample products loop
<ul class="products">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 12
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
@hemusyl
hemusyl / functions.php
Created March 3, 2017 23:41
TOTAL DOWNLOADS IN EASY DIGITAL DOWNLOADS // TOP SELLING ITEMS ON EDD
http://rubelmiah.com/show-top-selling-items-edd/
HOW TO SHOW TOP SELLING ITEMS ON EDD
<?php $popular_items = new WP_Query (array(
'post_type' => 'download',
'orderby' => 'meta_value_num',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_edd_download_sales',
'compare' => '>',
@hemusyl
hemusyl / functions.php
Created March 3, 2017 22:17
Search in Custom Post Types
https://developer.wordpress.org/themes/template-files-section/custom-post-type-template-files/
By default search results do not include custom post type content into the search results. The code can be appended to functions.php to include CPT in search results :
// Show posts of 'post', 'page', 'acme_product' and 'movie' post types on home page
function search_filter( $query ) {
if ( !is_admin() && $query->is_main_query() ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'post', 'page', 'acme_product', 'movie' ) );
}
}
@hemusyl
hemusyl / method-overlap.php
Created January 25, 2017 21:20 — forked from nahid/method-overlap.php
This gist is for PHP traits Example
<?php
trait Greetings
{
public function sayHello()
{
return 'Hello Bro';
}
public function goodBye()