Skip to content

Instantly share code, notes, and snippets.

View natejacobson's full-sized avatar

Nathan Jacobson natejacobson

  • Discovery Institute
  • Seattle, WA
View GitHub Profile
@natejacobson
natejacobson / dl-wp-nav-menu.php
Last active April 29, 2016 15:31
Datalist <dl> nav menu in WordPress
<nav>
<dl>
<?php
$menu_name = 'menu-name';
$locations = get_nav_menu_locations();
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) );
$count = 0;
<article>
<header>Article Header</header>
<center>
<p>Once upon a time...</p>
<ul></ul>
</center>
<footer>Article Footer</footer>
</article>
@natejacobson
natejacobson / datalist-accordion.html
Created July 7, 2015 23:56
Simple Datalist Accordion
<script>$('.folded dt').click( function() { $(this).toggleClass('unfolded').next('dd').toggleClass('unfolded'); });</script>
<style>
.folded dt,
.folded dd {
display: block;
}
.folded dt {
@natejacobson
natejacobson / prune_page_templates.php
Created June 23, 2015 18:28
Prune WordPress Template List in Child Theme
function prune_page_templates( $templates ) {
unset( $templates['templates/halves.php'] );
unset( $templates['templates/margin-left.php'] );
unset( $templates['templates/margin-right.php'] );
unset( $templates['templates/side-left.php'] );
unset( $templates['templates/side-right.php'] );
unset( $templates['templates/single.php'] );
return $templates;
}
add_filter( 'theme_page_templates', 'prune_page_templates' );
@natejacobson
natejacobson / section-backgrounds.js
Created June 12, 2015 21:21
Background Data to Style for WSU Spine Parent Theme
(function( $ ){
process_section_backgrounds = function() {
var $bg_sections = $('.section-wrapper-has-background');
$bg_sections.each( function() {
var background_image = $(this).data('background');
$(this).css('background-image', 'url(' + background_image + ')' );
});
};
@natejacobson
natejacobson / freshness_class.php
Last active August 29, 2015 14:17
Tag posts and pages with how recent they are in WordPress
// Assign to body on single pages and to each article in lists
add_filter( 'body_class', 'post_freshness_class' );
add_filter( 'post_class', 'post_freshness_class' );
function post_freshness_class( $classes ) {
$interval = ( current_time( 'Ymd', $gmt = 0 ) - get_the_date('Ymd') );
$interval_month = ( current_time( 'Ym', $gmt = 0 ) - get_the_date('Ym') );
if ( !is_page() ) {
@natejacobson
natejacobson / wp_image_figure_wrap.js
Last active August 29, 2015 14:17
Normalize WordPress images and figures by auto wrapping images and exposing assigned image classes on figure
function imageWrap() {
$("article img").each( function() {
var img_classes = $(this).attr("class");
var img_src = $(this).attr("src");
if ( !$(this).parent().is("figure") ) {
$(this).unwrap("p").wrap('<figure class="figure-auto figure-back '+img_classes+'" style="background-image: url(\''+img_src+'\')"></figure>');
@natejacobson
natejacobson / emailer.php
Last active August 29, 2015 14:16
PHP Mailer for Sending Test HTML Emails to Multiple Clients
<?php
$url = "http://example.com/email.html";
if ( $_GET["url"] != "" ) { $url = $_GET["url"]; }
// Determine Recipients
$recipients = $_GET["to"];
$to = "default.recipient@example.com";
// Desktop Clients
if ($recipients == "mail") { $to = "mail.user@example.com"; } // Apple Mail (Gold Standard)
@natejacobson
natejacobson / get_element_contents.php
Last active August 29, 2015 14:16
Get html or inner html for output elsewhere using php.
<?php
header("Content-Type: text/html; charset=utf-8");
function get_url_element_contents($url){
$crl = curl_init();
$timeout = 5;
curl_setopt ($crl, CURLOPT_URL,$url);
curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
$ret = curl_exec($crl);
curl_close($crl);
@natejacobson
natejacobson / gist:fccf376a805c49345a2a
Created January 16, 2015 00:39
Throwing array error.
function spine_excerpt_style_classes( $classes ) {
global $post;
if ( !is_singular() ) {
if ( $post->post_excerpt ) {
$classes[] = "summary-excerpted";
} elseif ( strstr( $post->post_content, '<!--more-->' ) ) {
$classes[] = "summary-divided";
} elseif ( 'excerpt' === spine_get_option( 'archive_content_display' ) ) {
$classes[] = "summary-truncated";