Skip to content

Instantly share code, notes, and snippets.

@zenman
zenman / snippet.php
Created February 19, 2014 18:28
Recent Posts Shortcode
<?php
/*
* Add recent posts shortcode. Use like so: [recent-posts posts='5' slug='uncategorized']
*/
function recent_posts_function($atts){
extract(shortcode_atts(array(
'posts' => 5,
'slug' => 'uncategorized'
), $atts));
@zenman
zenman / scrollTo.js
Created February 19, 2014 18:28
Easy jquery scrollTo anchor
jQuery(function($) {
var scrollElement = 'html, body';
$("a[href^='#']").click(function(event) {
event.preventDefault();
var $this = $(this),
target = this.hash,
@zenman
zenman / snippet.php
Created February 19, 2014 18:27
Pull a different page's content within the loop.
<?php
$page_id = 5;
$page_data = get_page( $page_id );
$content = apply_filters('the_content', $page_data->post_content);
$title = $page_data->post_title;
echo $content;
?>
@zenman
zenman / gist:9098305
Created February 19, 2014 18:26
ACF, display image only if there is one, include the alt title. Ensure the filed type in ACF is "Image Object"
<?php $img = get_field('FIELD_NAME_HERE'); if($img): ?>
<img src="<?php echo $img['url']; ?>" alt="<?php echo $img['alt']; ?>">
<?php endif; ?>
@zenman
zenman / ACF Repeater Gallery with Repeater.php
Created February 19, 2014 18:25
ACF :: Repeater field w/Fancybox Repeater field w/ Parent Image, Gallery Images & Caption
@zenman
zenman / gist:9098236
Created February 19, 2014 18:24
QR Code Gen
<a href="https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=<?php the_permalink() ?>" download="QRCode">Download this Code</a>
<div id="qrcode"></div>
<script type="text/javascript">
var img = document.createElement('img');
img.src = 'https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=' + encodeURIComponent(document.location.href);
@zenman
zenman / snippet.php
Created February 19, 2014 18:23
PHP in Text Widgets Function
//To use PHP code in a text widget (useful for links and conditionals), place this code in your theme's functions.php file.
add_filter('widget_text', 'php_text', 99);
function php_text($text) {
if (strpos($text, '<' . '?') !== false) {
ob_start();
eval('?' . '>' . $text);
$text = ob_get_contents();
.tabs{
margin: {top:40px;}
&:last-child{
margin: {bottom:80px;}
}
h2{
color: $color-1;
font: {
size: emCalc(36px);
}
@zenman
zenman / snippet.php
Created January 8, 2014 15:00
Gives you full control over comment structure and output.
/*
* Custom Comments
* Description: Use custom comments (overrides wp_list_comments like so: <?php wp_list_comments('type=comment&callback=mytheme_comment'); ?>)
*/
function mytheme_comment($comment, $args, $depth) {
$GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP);
if ('div' == $args['style']) {
$tag = 'div';
$add_below = 'comment';
<?php $the_query = new WP_Query('cat=3&posts_per_page=2'); ?>
<?php if ($the_query->have_posts()) : ?>
<?php while ($the_query->have_posts()) : $the_query->the_post(); ?>
output...
<?php endwhile; wp_reset_postdata();?>
<?php endif; ?>