Skip to content

Instantly share code, notes, and snippets.

View karlazz's full-sized avatar

Karla Leibowitz karlazz

  • herself
  • Walnut Creek, CA
View GitHub Profile
@karlazz
karlazz / gist:4571160
Created January 19, 2013 07:04
scheduling a task to test wp-cron
if (!wp_next_scheduled('my_task_hook')) {
wp_schedule_event( time(), 'hourly', 'my_task_hook' );
}
add_action( 'my_task_hook', 'my_task_function' );
function my_task_function() {
wp_mail('you@yoursite.com', 'Automatic email', 'Hello, this is an automatically scheduled email from WordPress.');
}
order allow,deny
deny from 64.64.2.102
allow from all
@karlazz
karlazz / Otto's settings example untested
Last active December 11, 2015 13:59
Use the add_settings and settings_field tags to create an options page. This is an example of a settings page from Otto on WordPress. I strung the code together from his post. I have not tried it yet. Some notes: seems like a lot of indirection to hide the fact that you are building a form : falls in the rewriting html category, since you have t…
<?php // add the admin options page
add_action('admin_menu', 'plugin_admin_add_page');
function plugin_admin_add_page() {
add_options_page('Custom Plugin Page', 'Custom Plugin Menu', 'manage_options', 'plugin', 'plugin_options_page');
}
?>
<?php // display the admin options page
function plugin_options_page() {
?>
<div>
@karlazz
karlazz / WordPress Standalone PHP
Last active June 14, 2021 01:30
Running WordPress functions as a standalone php file
<!DOCTYPE HTML>
<!-- attribution -- this blog provided the code
http://blog.makingsense.com/2011/03/create-stand-alone-web-pages-or-widgets-that-use-wordpress-functions/
-->
<?php
//required include files
require('wp-blog-header.php');
require_once("wp-config.php");
require_once("wp-includes/wp-db.php");
@karlazz
karlazz / gist:5217013
Created March 21, 2013 21:34
tags in a category by john anderson on the wordpress forum
function get_category_tags($args) {
global $wpdb;
$tags = $wpdb->get_results
("
SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, null as tag_link
FROM
wp_posts as p1
LEFT JOIN wp_term_relationships as r1 ON p1.ID = r1.object_ID
LEFT JOIN wp_term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
LEFT JOIN wp_terms as terms1 ON t1.term_id = terms1.term_id,
@karlazz
karlazz / gist:5241734
Created March 25, 2013 23:08
Make a finite scroll with Ajax. Not great but does the trick.
/* Finite scroll functions */
jQuery('.nextpage').click(function(){
var nextpageno=$('.nextpageno:last').html(); /* write this element with php into div, kind of hinky */
if (nextpageno>0) {
$('.inside').append($(document.createElement("div")).load('<?php echo $nextpagelink."/"?>' + nextpageno + ' .inside-left') );
}
});
jQuery(document).ajaxSend(function(event, request, settings) {
$('.nextpage').css("display","none");
@karlazz
karlazz / gist:6023009
Last active December 19, 2015 21:49
Drupal 7: Views PHP filter to select items allocated into two groups, randomly designate group to select
// FILTER: GLOBAL PHP
// SETUP CODE
global $randvalforslides;
$randvalforslides=rand(1,2);
// FILTER CODE ---------------------------------------------
$node = node_load($row->nid);
$fhg = $node->field_homepage_group;
$fhg1=$fhg['und'][0]['value'];
global $randvalforslides;
@karlazz
karlazz / gist:6081388
Last active December 20, 2015 05:49
Simple wp_query example
$random_post = new WP_query();
$random_post->query('cat=3&showposts=1&orderby=rand');
while ($random_post->have_posts()) : $random_post->the_post();
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<img src="<?php echo get_post_meta($random_post->ID, 'featured', true); ?>">
</a>
endwhile;
wp_reset_postdata();
@karlazz
karlazz / gist:6118140
Last active December 20, 2015 10:49
floating buttons
<!-- start floatingbuttons -->
<script src='http://apis.google.com/js/plusone.js' type='text/javascript'> {lang: &#39;en-US&#39;} </script>
<div id='floatingbuttons' title="Share this post!"><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><script type="text/javascript"> (function() { var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0]; s.type = 'text/javascript'; s.async = true; s.src = 'http://widgets.digg.com/buttons.js'; s1.parentNode.insertBefore(s, s1); })(); </script><!-- Medium Button --><script src='http://platform.twitter.com/widgets.js' type="text/javascript"></script>
<div class='floatbutton' id='facebook'><fb:like layout="box_count" show_faces="false" font=""></fb:like></div>
<div class='floatbutton' id='google+1'><g:plusone size="tall"></g:plusone></div>
<div class='floatbutton' id='stumbleupon'><script src="http://www.stumbleupon.com/hostedbadge.php?s=5"></script></div>
<div class='floatbutton' id='digg'><a class="DiggThisButton DiggM
@karlazz
karlazz / gist:7311956
Created November 5, 2013 00:44
Need this for Genesis 2.0 childtheme. Add to functions.php
/* SERIOUSLY? */
add_action( 'genesis_meta', 'sample_viewport_meta_tag' );
function sample_viewport_meta_tag() {
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0"/>';
}
add_theme_support( 'html5' );