Skip to content

Instantly share code, notes, and snippets.

View justinwhall's full-sized avatar

Justin W Hall justinwhall

View GitHub Profile
@justinwhall
justinwhall / WP.Pagination.php
Created March 6, 2012 23:24
PHP: Function WordPress Pagination
//PAGINATION//
/* Function that Rounds To The Nearest Value.
Needed for the pagenavi() function */
function round_num($num, $to_nearest) {
/*Round fractions down (http://php.net/manual/en/function.floor.php)*/
return floor($num/$to_nearest)*$to_nearest;
}
/* Function that performs a Boxed Style Numbered Pagination (also called Page Navigation).
Function is largely based on Version 2.4 of the WP-PageNavi plugin */
@justinwhall
justinwhall / gist:1997673
Created March 8, 2012 00:56
PHP: Function e-mail share
//email share function
function direct_email($text="Send by email"){
global $post;
$title = htmlspecialchars($post->post_title);
$excerpt = htmlspecialchars($post->the_excerpt);
$subject = 'Article by '.htmlspecialchars(get_bloginfo('name')).': '.$title . $excerpt;
$body = 'Check out this article from Justin W Hall: '.$title. "\n" . "\n" .get_permalink($post->ID);
$link = '<a rel="nofollow" href="mailto:?subject='.rawurlencode($subject).'&amp;body='.rawurlencode($body).'" title="'.$text.' : '.$title.'">'.$text.'</a>';
return $link;
}
@justinwhall
justinwhall / gist:1997684
Created March 8, 2012 00:59
PHP: Function WordPress Highlight Authour Comment
function author_highlight() {
global $comment;
if ($comment->user_id == get_the_author_meta('ID')) { echo "highlighted"; }
}
@justinwhall
justinwhall / gist:1997691
Created March 8, 2012 01:01
PHP: Function Latest Tweet
function display_latest_tweets(
$twitter_user_id = 'justinwhall',
$cache_file = 'twitter.txt',
$tweets_to_display = 1,
$ignore_replies = false,
$twitter_wrap_open = '<ul id="twitter">',
$twitter_wrap_close = '</ul>',
$tweet_wrap_open = '<li><span class="status">',
$meta_wrap_open = '</span><span class="meta"> ',
$meta_wrap_close = '</span>',
@justinwhall
justinwhall / class.my-theme-options.php
Created March 8, 2012 01:07
PHP: WordPress | theme options page
<?php
/**
* Master theme class
* @since 1.0
*/
class My_Theme_Options {
private $sections;
private $checkboxes;
@justinwhall
justinwhall / gist:1997780
Created March 8, 2012 01:16
PHP: WordPress | tinyMCE editor style dropdown menu
/**
* Filter TinyMCE Buttons
*
* Here we are filtering the TinyMCE buttons and adding a button
* to it. In this case, we are looking to add a style select
* box (button) which is referenced as "styleselect". In this
* example we are looking to add the select box to the second
* row of the visual editor, as defined by the number 2 in the
* mce_buttons_2 hook.
*/
@justinwhall
justinwhall / gist:1997787
Created March 8, 2012 01:18
PHP: Wordpress | replace defualt WP login logo
//Custom Login image
add_action("login_head", "my_login_head");
function my_login_head() {
echo "
<style>
body.login #login h1 a {
background: url('".get_bloginfo('template_url')."/images/newlogo.png') no-repeat scroll center top transparent;
height: 152px;
width: 330px;
}
@justinwhall
justinwhall / gist:1997794
Created March 8, 2012 01:19
PHP: WordPress | breadcrumbs
function wp_bac_breadcrumb() {
//Variable (symbol >> encoded) and can be styled separately.
//Use >> for different level categories (parent >> child >> grandchild)
$delimiter = '<span class="delimiter"> &raquo; </span>';
//Use bullets for same level categories ( parent . parent )
$delimiter1 = '<span class="delimiter1"> &bull; </span>';
//text link for the 'Home' page
$main = 'Home';
//Display only the first 30 characters of the post title.
@justinwhall
justinwhall / gist:1997825
Created March 8, 2012 01:23
PHP: WordPress | Get children pages AND the sibling pages ONLY when on child pages
<?php
// Get children pages AND the sibling pages ONLY when on child pages
if($post->post_parent)
$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0&sort_column=menu_order&depth=1");
else
$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&sort_column=menu_order&depth=1");
if ($children) :
?>
<div id="child-menu" >
<ul>
@justinwhall
justinwhall / uploader.js
Created March 8, 2012 01:34
jQuery: WordPress | Uploader for theme options page
jQuery(document).ready(function() {
jQuery('.st_upload_button').click(function() {
/* formfield = jQuery('#st_upload').attr('name'); */
targetfield = jQuery(this).prev('.upload-url');
tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
return false;
});
window.send_to_editor = function(html) {