Skip to content

Instantly share code, notes, and snippets.

var link = document.createElement('a');
link.href = 'images.jpg';
link.download = 'Download.jpg';
document.body.appendChild(link);
link.click();
@mzo84
mzo84 / Enqueue-jQuery.php
Created August 18, 2016 08:17
Wordpress Enqueue jQuery
// Put this PHP code into your functions.php le.
// This will load the jQuery library onto your page by inserting a link in the <head> section where you call wp_head.
if(!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/
jquery/1.3.2/jquery.min.js"), false, '1.3.2');
wp_enqueue_script('jquery');
}
@mzo84
mzo84 / random-post.php
Created August 18, 2016 08:14
Wordpress - listing random possts
<?php // display random posts
$home_brew = new WP_Query('showposts=3&orderby=rand');
while($home_brew->have_posts()) : $home_brew->the_post();
// output custom stuff here! Post title, content, custom elds..
endwhile;
wp_reset_postdata();
?>
@mzo84
mzo84 / flexbox.css
Last active August 18, 2016 05:53
less damn code
// element margins
body * + * {
margin-top: 1.5rem;
}
// grid
.grid {
display: flex;
flex-flow: row wrap;
}
@mzo84
mzo84 / get_posts.php
Last active August 16, 2016 07:08
Customizing the Loop with get_posts
<?php // additional loop via get_posts
global $post;
$args = array('category' => -9); // exclude Asides category
$custom_posts = get_posts($args);
foreach($custom_posts as $post) : setup_postdata($post);
...
endforeach;
?>
@mzo84
mzo84 / WP_Query-multiple-loops.php
Created August 16, 2016 06:34
Using WP_Query to create and customize multiple loops.
<?php // Loop 1
$ rst_query = new WP_Query('cat=-1'); // exclude category
while($ rst_query->have_posts()) : $ rst_query->the_post();
...
endwhile;
wp_reset_postdata(); // reset the query
// Loop 2
$second_query = new WP_Query('cat=-2'); // exclude category
while($second_query->have_posts()) : $second_query->the_post();
...
@mzo84
mzo84 / WP-Query.php
Created August 16, 2016 06:33
Customizing the Loop with WP_Query
<?php // The WordPress Loop - customized with WP_Query
$custom_query = new WP_Query('cat=-9'); // exclude Asides category
while($custom_query->have_posts()) : $custom_query->the_post();
...
endwhile;
wp_reset_postdata(); // reset the query
?>
// more examples
<?php
@mzo84
mzo84 / query-posts.php
Created August 16, 2016 06:28
wordpress - query posts
<?php // The WordPress Loop - customized with query_posts
global $query_string; // grab the global query information
$posts = query_posts($query_string.'&cat=-9'); // exclude Asides category
if (have_posts()) : while (have_posts()) : the_post();
...
endwhile; else:
...
endif;
wp_reset_query(); // reset the query
?>
@mzo84
mzo84 / page-custom-fields.php
Created August 15, 2016 11:46
wordpress - custom field on page
// when adding a custom field to a page, you can check its value like this:
<?php // e.g conditional sidebar display
if (!get_post_meta($post->ID, "noSidebar", true)) {
get_sidebar();
} ?>
@mzo84
mzo84 / loop-query.php
Last active August 15, 2016 11:33
wordpress - To check what query string is being used by the Loop
// To check what query string is being used by the Loop
// insert before the loop.
<?php echo "<pre>"; print_r($wp_query->query_vars); echo "</pre>"; ?>