Skip to content

Instantly share code, notes, and snippets.

View whatjackhasmade's full-sized avatar
🏄‍♂️
Surfing the www.

Jack Pritchard whatjackhasmade

🏄‍♂️
Surfing the www.
View GitHub Profile
@whatjackhasmade
whatjackhasmade / archived_posts.php
Created July 21, 2017 11:06
Use The Loop To Create An “Archive” Page Template The problem. As noted in the previous hack, a common problem on blogs is that it is hard for readers to find content published a while ago. To help my readers finding what they’re looking for, I created a WordPress page template that displays a list of all posts ever published on my blog. You can…
<?php
/*
Template Name: Archives
*/
?>
<?php get_header(); ?>
<h2><?php $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish'");
if (0 < $numposts) $numposts = number_format($numposts); ?>
@whatjackhasmade
whatjackhasmade / posts_last_year.php
Created July 21, 2017 11:05
Display Posts Published One Year Ago
<?php
$current_day = date('j');
$last_year = date('Y')-1;
query_posts('day='.$current_day.'&year='.$last_year);
if (have_posts()):
while (have_posts()) : the_post();
the_title();
the_excerpt();
endwhile;
endif;
@whatjackhasmade
whatjackhasmade / posts_with_custom_value.php
Created July 21, 2017 11:03
Get Posts With A Specific Custom Field And Specific Value
<?php query_posts('meta_key=review_type&meta_value=movie'); ?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
@whatjackhasmade
whatjackhasmade / exclude_posted_posts.php
Created July 21, 2017 11:02
Use More Than One Loop On A Page, Without Printing Duplicate Posts
<?php
query_posts('showposts=8');
$ids = array();
while (have_posts()) : the_post();
$ids[] = get_the_ID();
the_title();
the_content();
endwhile;
?>
@whatjackhasmade
whatjackhasmade / post_dates.php
Created July 21, 2017 11:00
Get Posts Published Between Two Dates The loop and the query_posts() WordPress function allow you to easily retrieve a list of posts published in a specific week or month. Unfortunately, getting posts published between, for example, March 17 and May 3 isn’t that easy. Let’s solve this problem.
<?php
function filter_where($where = '') {
$where .= " AND post_date >= '2009-03-17' AND post_date <= '2009-05-03'";
return $where;
}
add_filter('posts_where', 'filter_where');
query_posts($query_string);
while (have_posts()) :
the_post();
the_content();
@whatjackhasmade
whatjackhasmade / functions.php
Last active June 6, 2017 09:22
Allow SVG files to be uploaded to the media library
// Allow SVG files to be uploaded to the media library
add_filter( 'wp_check_filetype_and_ext', function($data, $file, $filename, $mimes) {
global $wp_version;
if ( $wp_version !== '4.7.1' ) {
return $data;
}
$filetype = wp_check_filetype( $filename, $mimes );
@whatjackhasmade
whatjackhasmade / functions.php
Created June 5, 2017 16:57
Include additional pages to wordpress admin dashboard
function register_my_custom_menu_page() {
add_menu_page( 'Page Title', 'Menu Title', 'manage_options', '../wp-content/themes/index.html', '', 'dashicons-book', 3 );
}
add_action( 'admin_menu', 'register_my_custom_menu_page' );
@whatjackhasmade
whatjackhasmade / functions.php
Created June 5, 2017 11:18
functions.php - Remove JQuery/Migrate and WP Embed
// Remove jQuery Migrate Script from header and Load jQuery from Google API
function crunchify_stop_loading_wp_embed_and_jquery() {
if (!is_admin()) {
wp_deregister_script('wp-embed');
wp_deregister_script('jquery'); // Bonus: remove jquery too if it's not required
}
}
add_action('init', 'crunchify_stop_loading_wp_embed_and_jquery');
@whatjackhasmade
whatjackhasmade / functions.php
Created June 5, 2017 11:17
functions.php - Remove WP Emoji
// Remove WP Emoji
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
@whatjackhasmade
whatjackhasmade / media-queries.scss
Last active June 5, 2017 11:12
Mixin - Media Queries
/*/////////////////////////////////////////
/// MEDIA QUERIES
*/////////////////////////////////////////
/**
* Mixins for defining media queries. These mixins should always be used
* to define media query breakpoints.
*/
@mixin bp-min-width($width) {