This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# Use the 11ty universal filters to fetch the previous and next items in a collection #} | |
{% set previousPost = collections.service | getPreviousCollectionItem(page) %} | |
{% set nextPost = collections.service | getNextCollectionItem(page) %} | |
{% if not previousPost %} | |
{# if there is not a previous post this must be the first post so let us grab the last post instead #} | |
{% set previousPost = collections.service | last %} | |
{% endif %} | |
{% if not nextPost %} | |
{# if there is not a next post this must be the last post so let us grab the first post instead #} | |
{% set nextPost = collections.service | first %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_child_terms ( $term, $tax ) { | |
$child_terms = array(); | |
if( $term && $tax ) { | |
$the_term = get_term_by( 'slug', $term, $tax ); // Get term object using the slug | |
$terms = get_the_terms(get_the_ID(), $tax); // Get the terms attached to the post | |
if( $the_term && $terms ) { | |
foreach ( $terms as $term ) { | |
if( $the_term->term_id == $term->parent ) { | |
$child_terms[] = $term->name; // Only get the terms where the parent is the current term |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function referer_term( $taxonomy ) { | |
$term = null; | |
$referer = wp_get_referer(); // Get the referer URL | |
if( $referer ) { | |
// Here we parse the URL extracting the path element of it | |
$referer_path = parse_url( $referer, PHP_URL_PATH ); | |
if( $referer_path && $taxonomy ) { | |
// If we have a path and a taxonomy we are good to go | |
if ( strpos( $referer_path, $taxonomy ) !== false ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function geolocation( $address ) { | |
$coordinates = null; | |
if( $address ) { | |
$address = rawurlencode( $address ); // Returns a string in which all non-alphanumeric characters except -_.~ have been replaced with a percent (%) sign followed by two hex digits. | |
$key = 'YOUR_API_KEY'; // The Geolocation API Key | |
$url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . $address . '&key=' . $key; | |
$data = file_get_contents( $url ); // Get the JSON file. | |
if ( $data ) { | |
$json = json_decode( $data, true ); // Turns the JSON into an array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'init', 'import_products', 20 ); | |
function import_products() { | |
$products = array( | |
array( 'title' => 'AFDD060630B', 'description' => 'AFDD RCBO 10A 30mA 1P+N TYPE A', 'term' => 'Switch'), | |
array( 'title' => 'AFDD061030B', 'description' => 'AFDD RCBO 12A 30mA 1P+N TYPE A', 'term' => 'Large Dial'), | |
array( 'title' => 'AFDD061630B', 'description' => 'AFDD RCBO 16A 30mA 1P+N TYPE A', 'term' => 'Rotor') | |
); | |
$user = get_user_by('login', 'your-username'); | |
$user_id = $user->ID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$taxonomy = 'taxonomy'; | |
if( has_term( '', $taxonomy ) ) { | |
$terms = get_the_terms( $post->ID, $taxonomy ); | |
$term = array_shift( $terms ); | |
$term_link = get_term_link( $term->term_id ); | |
$term_name = $term->name; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Takes a complete URL and returns the user handle | |
* created for Instagram but also likely to work for other social channels | |
**/ | |
function get_handle( $url ) { | |
$url = rtrim( $url, '/' ); | |
$parse = parse_url( $url ); | |
$path = $parse['path']; | |
$path = ltrim( $path, '/' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set image = profile.name | lower | replace(" ", "-") %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function archive_tax_name() { | |
$archive_tax_name = null; | |
if( is_archive() && is_category() ) { | |
$queried_object = get_queried_object(); | |
$queried_object_taxonomy = $queried_object->taxonomy; | |
$taxonomy = get_taxonomy($queried_object_taxonomy); | |
$archive_tax_name = $taxonomy->labels->singular_name; | |
} | |
return $archive_tax_name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Sets the default categories | |
function add_the_categories() { | |
$categories = array( | |
'Case Study', | |
'Blog', | |
'Article' | |
); | |
foreach( $categories as $category ) { | |
$exists = term_exists( $category, 'category' ); |
NewerOlder