Skip to content

Instantly share code, notes, and snippets.

View justiny's full-sized avatar

Justin Young justiny

View GitHub Profile
<?php
// Taxonomy Object
$gift_guide_products = get_field('gift_guide_collection');
$args = array(
'post_type' => 'product',
'posts_per_page' => 12,
'tax_query' => array(
array(
// Custom Taxonomy
'taxonomy' => 'gift-guide-collection',
@justiny
justiny / latest-posts-from-cat.php
Last active December 7, 2018 16:29
Get latest posts from category, excluding current post
<?php
// convert to timber
$current_post_id = get_the_ID();
$current_post_cats = get_the_category();
$current_post_first_cat_id = $current_post_cats[ 0 ]->term_id;
$args = array(
'cat' => $current_post_first_cat_id,
@justiny
justiny / page.php
Last active September 28, 2018 20:10
Flexible Content in ACF & Timber
<?php
use Timber\Timber;
$context = Timber::get_context();
$context['post'] = $post;
$post = new TimberPost();
Timber::render( array(
'core/page-' . $post->post_name . '.twig',
'core/page.twig' ),
@justiny
justiny / blog.php
Last active September 26, 2018 18:25
Blog with Pagination in Timber
<?php
/**
* Template Name: Blog
**/
global $paged;
if (!isset($paged) || !$paged){
$paged = 1;
}
@justiny
justiny / flexbox-absolute-centered
Last active December 31, 2017 21:18
Flexbox Absolute Centered Div
/* Vertical align
https://chriswrightdesign.com/experiments/flexbox-adventures/#
*/
.d-flex-vertical {
/* Tell flexbox to start vertically from the center */
align-items:center;
display:flex;
/* I'm also aligning it horizontally */
justify-content:center;
@justiny
justiny / ACF Accordion Bootstrap 4
Created May 24, 2017 21:07
Simple Accordion for Bootstrap 4 + Advanced Custom Fields
<div id="accordion" role="tablist" aria-multiselectable="true">
<?php if( have_rows('service_accordion', 'options') ): ?>
<?php $i=0; while ( have_rows('service_accordion', 'options') ) : the_row(); ?>
<?php $string = sanitize_title( get_sub_field('service_title', 'options') );
$service_content = get_sub_field('service_content', 'options'); ?>
<div class="card">
<div class="card-header" role="tab" id="headingTwo">
<h5 class="mb-0">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#<?php echo $string ?>" aria-expanded="false" aria-controls="<?php echo $string ?>">
<?php the_sub_field('service_title', 'options'); ?>
@justiny
justiny / Metabox Deluxe Taxonomy in Query
Created January 6, 2015 02:03
Show posts from multiple categories in query using Metabox Deluxe
<?php $categories = rwmb_meta( 'gt_meta_value', 'type=taxonomy&taxonomy=category' );
$cat_num = get_post_meta($post->ID, 'gt_cat_num', TRUE);
foreach ( $categories as $category ){
$cat_ids[] = $category->term_id;
}
$i = 1;
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} else if ( get_query_var('page') ) {