WordPress Widget Basic Structure
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
<?php error_reporting(E_ALL); /* Plugin Name: Messenger Widget Plugin URI: http://www.scoldy.com Description: Any message designated. Version: 1.0 Author: Ronnie Author URI: http://www.scoldy.com */ class Messager extends WP_Widget { function __construct() { } public function form() { } public function widget() { } } ?> |
Source: Snipplr
Get all custom taxonomies that are attached to posts that have another custom taxonomy
The following WordPress snippets will let you get all custom taxonomies which are attached to posts which have another custom taxonomy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
<?php include('wp-load.php'); $nike = get_term_by('slug','nike','brand'); // This here just to illustrate $terms = get_cross_referenced_terms(array( 'post_type' => 'product', 'related_taxonomy' => 'brand', 'term_id' => $nike->term_id, )); foreach($terms as $term) { echo "<p>{$term->name}</p>"; } function get_cross_referenced_terms($args) { global $wpdb; $args = wp_parse_args($args,array( 'post_type' => 'post', 'taxonomy' => 'category', 'related_taxonomy' => 'post_tag', 'term_id' => 0, )); extract($args); $sql = <<<SQL SELECT DISTINCT {$wpdb->terms}.*, COUNT(*) AS post_count FROM {$wpdb->terms} INNER JOIN {$wpdb->term_taxonomy} ON {$wpdb->terms}.term_id={$wpdb->term_taxonomy}.term_id INNER JOIN {$wpdb->term_relationships} ON {$wpdb->term_taxonomy}.term_taxonomy_id={$wpdb->term_relationships}.term_taxonomy_id INNER JOIN {$wpdb->posts} ON {$wpdb->term_relationships}.object_id={$wpdb->posts}.ID INNER JOIN {$wpdb->term_relationships} related_relationship ON {$wpdb->posts}.ID=related_relationship.object_id INNER JOIN {$wpdb->term_taxonomy} related_term_taxonomy ON related_relationship.term_taxonomy_id=related_term_taxonomy.term_taxonomy_id INNER JOIN {$wpdb->terms} related_terms ON related_term_taxonomy.term_id=related_terms.term_id WHERE 1=1 AND (related_term_taxonomy.taxonomy<>{$wpdb->term_taxonomy}.taxonomy OR related_terms.term_id<>{$wpdb->terms}.term_id) AND {$wpdb->posts}.post_type='%s' AND {$wpdb->term_taxonomy}.taxonomy='%s' AND related_term_taxonomy.taxonomy='%s' AND related_terms.term_id=%d GROUP BY {$wpdb->terms}.term_id SQL; $sql = $wpdb->prepare($sql,$post_type,$taxonomy,$related_taxonomy,$term_id); $terms = $wpdb->get_results($sql); return $terms; } |
Source: Stackxchange
Anti-Word Alert
The following snippet will alert on anti-words
1 2 3 4 5 6 7 8 9 10 11 |
add_action( 'admin_notices', 'custom_admin_notice' ); function custom_admin_notice(){ global $current_screen; if ( $current_screen->parent_base == 'edit' ) echo '<div class="updated"><p><strong>NOTE</strong> - Please do not copy and paste text from Microsoft Word. You can write and save your post here in WordPress, or copy it from a plain text app (Notepad or TextEdit). Microsoft Word adds a ton of messy inline tags that break things.</p></div>'; } |
WordPress AJAX loop template
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
<?php // Our include define('WP_USE_THEMES', false); require_once('../../../wp-load.php'); // Our variables $numPosts = (isset($_GET['numPosts'])) ? $_GET['numPosts'] : 0; $page = (isset($_GET['pageNumber'])) ? $_GET['pageNumber'] : 0; $catSlug = (isset($_GET['catSlug'])) ? $_GET['catSlug'] : 0; $count = 0; global $query_string; $args = wp_parse_args($query_string); if($catSlug=='all'){ $args = array( 'post_type' => 'post', 'paged' => $page, 'posts_per_page' => $numPosts, 'post_status' => 'publish', ); }else{ $args = array( 'category_name' => $catSlug, 'post_type' => 'post', 'paged' => $page, 'posts_per_page' => $numPosts, 'post_status' => 'publish', ); } ?> <?php $wp_query = new WP_Query( $args ); ?> <?php $totalposts = $wp_query->post_count; while ($wp_query->have_posts()) : $wp_query->the_post(); $count++; ?> <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?> role="article" itemscope itemtype="http://schema.org/BlogPosting"> <header class="article-header"> <div class="date"><?php print get_the_time('j-m-Y'); ?></div> <h1 class="news-title"><?php the_title(); ?></h1> <?php $postid = get_the_ID(); ?> <p class="byline vcard"> Posted in <?php echo get_cats($postid); ?> by <?php echo get_the_author(); ?> </p> </header> <!-- end article header --> <section class="entry-content clearfix" itemprop="articleBody"> <?php the_content(); ?> </section> <!-- end article section --> </article> <!-- end article --> <?php endwhile; wp_reset_query(); ?> |
Source: Snipplr
Add Custom Menu Support
The following snippet will add custom menu support
1 2 3 4 5 6 7 |
add_action('init', 'register_custom_menu'); function register_custom_menu() { register_nav_menu('custom_menu', __('Custom Menu')); } |
Source: ThinkVitamin
Increase server memory limit in wp-config.php
The following snippet will increase server memory limit in wp-config.php file
1 2 3 4 5 6 7 |
/** * Increase memory limit */ define('WP_MEMORY_LIMIT', '256M'); |
Source: Snipplr
Get Image Path Relevant To Theme
The following snippet will get image path relevant to theme
1 |
<img src="<?php bloginfo('template_directory'); ?>/images/XXX.jpg" title="" alt="" /> |
Source: BrightCherry.co.uk