Skip to content

Instantly share code, notes, and snippets.

@brettsnippets
brettsnippets / ajax-call.js
Created May 19, 2013 17:33
JavaScript: jQuery Ajax Call
$.ajaxSetup({cache:false});
$("a.linkContainingUrl").click(function(){
var post_url = $(this).attr('href');
var post = $('#post-here');
post.html('<img src="../img/ajax-loader.gif" />'); /* shows ajax loader until content is loaded */
post.load(post_url + ' #pull-this-content');
/* within the #post-here div, this will load in the post url from the a:link being clicked,
@brettsnippets
brettsnippets / gist:5615798
Last active December 17, 2015 13:19
WordPress: is_tree
//Page List Navigation
function my_page_tree($this_page) {
$pagelist = '';
if( !$this_page->post_parent ) {
$children = wp_list_pages('sort_column=menu_order&exclude=430&title_li=&child_of='.$this_page->ID.'&echo=0');
if( $children ) {
$pagelist .= '<li class="current_page_item"><a href="'. get_page_link($this_page->ID) .'">' . $this_page->post_title . '</a>';
$pagelist .= '<ul>' . $children . '</ul>';
$pagelist .= '</li>';
}
@brettsnippets
brettsnippets / excerpt.php
Created May 20, 2013 21:41
WordPress: Custom Excerpt
function get_custom_excerpt($length) {
$excerpt = get_the_content();
$excerpt = preg_replace(" (\[.*?\])",'',$excerpt);
$excerpt = strip_shortcodes($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = substr($excerpt, 0, $length);
$excerpt = substr($excerpt, 0, strripos($excerpt, " "));
$excerpt = trim(preg_replace( '/\s+/', ' ', $excerpt));
$excerpt = $excerpt.'...';
return $excerpt;
@brettsnippets
brettsnippets / gist:5616007
Created May 20, 2013 22:10
WordPress: Is user logged in
<?php
if(is_user_logged_in()) {
// do something
} else {
// do something else
}
?>
@brettsnippets
brettsnippets / cycle.html
Created May 20, 2013 23:41
Cycle Example
<ul id="slider" class="row-fluid cycle-slideshow addShadow" data-cycle-slides="li" data-cycle-pause-on-hover="true" data-cycle-fx="scrollHorz" data-cycle-swipe="true">
<div class="cycle-pager"></div>
<li class="cycle-slide">
<a href="#"><img width="940" height="435" src="http://football.brett-marshall.com/assets/geno.jpg" class="attachment-slider_image wp-post-image" alt="geno"></a>
<div class="slide-content container">
<div class="row-fluid">
<div class="span12">
<div class="row-fluid">
<div class="span8">
<h2><a href="#">Headline, QB Geno Smith?</a></h2>
@brettsnippets
brettsnippets / ajax.js
Created May 21, 2013 19:11
JavaScript: Ajax Call, Using Push State & Disqus Commenting Reload
$.ajaxSetup({cache:false});
$(document).on("click", ".resource-listing a.read-more", function(){
if(Modernizr.history) {
var post_url = $(this).attr('href');
var post = $('#main-content');
post.html('<img src="/wp-content/themes/funding/assets/img/ajax-loader.gif" class="ajax-loader"/>'); /* shows ajax loader until content is loaded */
post.load(post_url + ' #pull-this-content', function() {
@brettsnippets
brettsnippets / word-wrap.css
Created May 28, 2013 18:28
CSS: Link Word Wrap
white-space: pre;
white-space: pre-wrap;
white-space: pre-line;
white-space: -pre-wrap;
white-space: -o-pre-wrap;
white-space: -moz-pre-wrap;
white-space: -hp-pre-wrap;
word-wrap: break-word;
@brettsnippets
brettsnippets / custom_list_pages.php
Created May 28, 2013 20:25
WordPress: wp_list_pages | Custom Post Type | Class Names
function kct_page_css_class( $css_class, $page, $depth, $args, $current_page ) {
if ( !isset($args['post_type']) || !is_singular($args['post_type']) )
return $css_class;
global $post;
$current_page = $post->ID;
$_current_page = $post;
_get_post_ancestors($_current_page);
if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) )
@brettsnippets
brettsnippets / flexbox.css
Created June 29, 2013 06:38
Flexbox "Cross Browser" Sample
.content {
display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */
display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */
display: -ms-flexbox; /* TWEENER - IE 10 */
display: -webkit-flex; /* NEW - Chrome */
display: flex;
-webkit-flex-direction: column;
-moz-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
@brettsnippets
brettsnippets / smooth.js
Created July 10, 2013 15:48
Smooth Scroll
var smooth = {
Scroll: function(item, speed) {
// when the item is clicked
item.click(function() {
// grab the html document and / or the body
$("html, body").animate({
// grab the item clicked's href and get the distance between this element
//and the element it is scrolling to
scrollTop: $($(this).attr("href")).offset().top + "px"
}, {