Skip to content

Instantly share code, notes, and snippets.

@psflannery
psflannery / Add class to every third post
Created May 10, 2013 16:15
Adds a class to every nth post -- Wordpress
<?php if (have_posts()) : ?>
<?php $c = 0;while (have_posts()) : the_post(); $c++;
if( $c == 3) {
$style = 'third';
$c = 0;
}
else $style='';
// this goes in the loop
?>
@psflannery
psflannery / image sizes in WP uploader
Created May 12, 2013 13:47
Add new image sizes to the media upload/insert interface.
// http://pippinsplugins.com/add-custom-image-sizes-to-media-uploader/
function pw_add_image_sizes() {
add_image_size( 'pw-thumb', 300, 100, true );
add_image_size( 'pw-large', 600, 300, true );
}
add_action( 'init', 'pw_add_image_sizes' );
function pw_show_image_sizes($sizes) {
$sizes['pw-thumb'] = __( 'Custom Thumb', 'pippin' );
<?php $recent = new WP_Query("page_id=**ID**"); while($recent->have_posts()) : $recent->the_post();?>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php endwhile; ?>
@psflannery
psflannery / auto_twitter_link.php
Last active December 18, 2015 02:39
Once you saved the file all twitter usernames in posts and comments will automatically be linked to their Twitter profiles. Usernames have to be written under the form @username. @link: http://www.wpbeginner.com/wp-tutorials/how-to-automatically-link-twitter-usernames-in-wordpress/
@psflannery
psflannery / image_preloader
Created June 18, 2013 15:25
Ever noticed how fast images load when paging through a Facebook photo album? This is because Facebook is preloading each of these images into your browser’s cache before you even view them. Here’s how you can achieve a similar behavior on your website using some jQuery magic. - http://www.nealgrosskopf.com/tech/thread.php?pid=77
var nextimage = "/images/some-image.jpg";
$(document).ready(function(){
window.setTimeout(function(){
var img = $("<img>").attr("src", nextimage).load(function(){
//all done
});
}, 100);
});
@psflannery
psflannery / clickable_parent_div
Created June 18, 2013 15:27
Here’s an easy way to make the parent div of a link clickable. Let’s say you have this html code - http://css-tricks.com/snippets/jquery/make-entire-div-clickable/
/**
<div class="myBox">
blah blah blah.
<a href="http://google.com">link</a>
</div>
*/
$(".myBox").click(function(){
window.location=$(this).find("a").attr("href");
return false;
@psflannery
psflannery / thumb_background.php
Created June 23, 2013 18:35
Sets the thumbnail image as background to a div
<header class="entry-header row" <?php
if ( $thumbnail_id = get_post_thumbnail_id() ) {
if ( $image_src = wp_get_attachment_image_src( $thumbnail_id, 'x-large-size' ) )
printf( ' style="background-image: url(%s);"', $image_src[0] );
}
?>>
@psflannery
psflannery / tax_visual_editor
Created July 17, 2013 15:43
Adds a visual editor to the description field for custom taxonomies. Example below will display the tinymce editor in every custom taxonomy description right now. Can edit to show it for only some specific taxonomy. See also - http://wordpress.org/plugins/rich-text-tags/
/**
* Display advanced TinyMCE editor in taxonomy page
*/
function wpse_7156_enqueue_category() {
global $pagenow, $current_screen;
if( $pagenow == 'edit-tags.php' ) {
require_once(ABSPATH . 'wp-admin/includes/post.php');
require_once(ABSPATH . 'wp-admin/includes/template.php');
var replaced = $("body").html().replace(/-1o9-2202/g,'The ALL new string');
$("body").html(replaced);
//or, as a one liner
$("body").html($("body").html().replace(/12345-6789/g,'<b>abcde-fghi</b>'));
//replace every word
$("body").html($("p").html().replace(/[a-zA-Z0-9_]\w/g,'<b>oh hai!!!</b>'));
@psflannery
psflannery / video.php
Created August 21, 2013 12:59
A template for displaying video attachments. Add the video code inside the loop where we’d like to display the content within.
<video class="my-video-class">
<source src="<?php echo wp_get_attachment_url( $post->ID ) ?>" type='video/mp4' />
Your browser does not support the video tag.
</video>