WordPress AJAX jQuery script
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 106 107 108 109 110 111 |
// ajaxLoop.js jQuery(function($){ function reQuery(){ var thisDomain = 'http://davocom'; // no end slash var page = 1; var loading = true; var $window = $(window); var $content = $('.ajaxContent'); var load_posts = function(){ $.ajax({ type : 'GET', data : {numPosts : 6, pageNumber: page}, dataType : 'html', url : thisDomain+"/wp-content/themes/.../ajaxLoop.php", beforeSend : function(){ if(page != 1){ $content.append('<div id="temp_load" style="text-align:center">\ <img src="../images/ajax-loader.gif" />\ </div>'); } }, success : function(data){ $data = $(data); if($data.length){ $data.hide(); $content.html($data); $data.fadeIn(500, function(){ $("#temp_load").remove(); loading = false; }); $('ul.categories li a').removeClass('strong'); $('ul.categories li.category-'+arg+' a').addClass('strong'); } else { $("#temp_load").remove(); } }, error : function(jqXHR, textStatus, errorThrown) { $("#temp_load").remove(); alert(jqXHR + " :: " + textStatus + " :: " + errorThrown); } }); } $window.scroll(function() { var content_offset = $content.offset(); //console.log(content_offset.top); if(!loading && ($window.scrollTop() + $window.height()) > ($content.scrollTop() + $content.height() + content_offset.top)) { loading = true; page++; load_posts(); } }); load_posts(); } }); |
Source: Snipplr
WordPress Child Theme
The following snippet will let you sort out the stylesheet
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/* Theme Name: Child Theme Name Description: Description of your Child Theme Author: Your name here Template: folder */ @import url("../parentthemefolder/style.css"); |
Source: doitwithwp.com
Gravatar Image as Favicon
The following snippet will let you have your Gravatar image as WordPress Favicon
1 2 3 4 5 6 7 |
function GravatarAsFavicon() { $GetTheHash = md5(strtolower(trim('you@yourdomain.com'))); echo 'http://www.gravatar.com/avatar/' . $GetTheHash . '?s=16'; } |
Source: Forrst
Check if current post type is a custom post type
The following snippet will let you check if current post type is a custom post type or not
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
function is_custom_post_type() { global $wp_query; $post_types = get_post_types(array('public' => true,'_builtin' => false),'names','and'); foreach ($post_types as $post_type ) { if (get_post_type($post_type->ID) == get_post_type($wp_query->post->ID)) { return true; } else { return false; } } } |
Source: Snipplr
Move the posts count inside the link of the Archive and Category widgets
The following snippet will let you move the posts count inside the links of the archive and category widgets
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 |
<?php /* This code filters the Categories archive widget to include the post count inside the link */ add_filter('wp_list_categories', 'cat_count_span'); function cat_count_span($links) { $links = str_replace('</a> (', ' (', $links); $links = str_replace(')', ')</a>', $links); return $links; } /* This code filters the Archive widget to include the post count inside the link */ add_filter('get_archives_link', 'archive_count_span'); function archive_count_span($links) { $links = str_replace('</a> (', ' (', $links); $links = str_replace(')', ')</a>', $links); return $links; }?> |
Source: Github
Custom Menus in WordPress
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
register: <?php register_nav_menus( array( 'primary' => __( 'Primary Navigation', 'primarynav' ), 'secondary' => __( 'Secondary Navigation', 'secondarynav' ), 'footer' => __( 'Footer Navigation', 'footernav' ), ) ); ?> display: <?php wp_nav_menu(array( 'theme_location' => 'footer')); ?> |
Source: Snipplr
Alert Shortcodes
The following snippet will alert shortcodes
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 106 107 108 109 110 111 112 113 114 115 116 117 |
// Alert Shortcodes function alert_green($atts, $content = null) { return'<div class="alert-green">' . $content . '</div>'; } add_shortcode('alert_green', 'alert_green'); function alert_blue($atts, $content = null) { return'<div class="alert-blue">' . $content . '</div>'; } add_shortcode('alert_blue', 'alert_blue'); function alert_yellow($atts, $content = null) { return'<div class="alert-yellow">' . $content . '</div>'; } add_shortcode('alert_yellow', 'alert_yellow'); function alert_red($atts, $content = null) { return'<div class="alert-red">' . $content . '</div>'; } add_shortcode('alert_red', 'alert_red'); /* Alert Shortcodes */ /* Buttons, message boxes, & alert boxes */ .alert-green { -moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px; background:#e5ffcc url(images/alert_green.png) left center no-repeat; color:#573; border:1px solid #bbdd99; padding:10px 10px 10px 40px; margin:10px 0 20px 0; } .alert_blue { -moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px; background:#e5f5ff url(images/alert_blue.png) left center no-repeat; color:#467; border:1px solid #bde; padding:10px 10px 10px 40px; margin:10px 0 20px 0; } .alert_yellow { -moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px; background:#ffd url(images/alert_yellow.png) left center no-repeat; color:#664; border:1px solid #ddc; padding:10px 10px 10px 40px; margin:10px 0 20px 0; } .alert_red { -moz-border-radius:3px; -webkit-border-radius:3px; border-radius:3px; background:#fcc url(images/alert_red.png) left center no-repeat; color:#744; border:1px solid #daa; padding:10px 10px 10px 40px; margin:10px 0 20px 0; } |
WordPress Snippets Source: Snipplr