Skip to content

Instantly share code, notes, and snippets.

@raaar
raaar / css
Created July 27, 2012 10:54
WORDPRESS: Image Allignment
/* =WordPress Core
-------------------------------------------------------------- */
.alignnone {
margin: 5px 20px 20px 0;
}
.aligncenter,
div.aligncenter {
display: block;
margin: 5px auto 5px auto;
@raaar
raaar / html
Created July 27, 2012 15:42
WORDPRESS: List of Taxonomy itemes
<?php
//list terms in a given taxonomy
$taxonomy = 'news-category';
$tax_terms = get_terms($taxonomy);
?>
<ul class="categories">
<?php
foreach ($tax_terms as $tax_term) {
echo '<li><h3>' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a><h3></li>';
}
@raaar
raaar / php
Created July 28, 2012 13:50
WORDPRESS: Loop Custom Taxonomy in custom Post type
<?php // loop for taxonomy in custom post-type
$argsMine = array(
'numberposts' => -1,
'orderby' => 'desc',
'post_type' => 'info',
'section' => 'minesweeper',
'post_status' => 'publish'
);
$postslist = get_posts($argsMine);
foreach ($postslist as $post) :
@raaar
raaar / php
Created August 2, 2012 11:41
WORDPRESS: Get post thumbnail
<?php
// check if the post has a Post Thumbnail assigned to it.
if ( has_post_thumbnail() ) {
the_post_thumbnail('thumbnail');
}
?>
@raaar
raaar / php
Created August 3, 2012 11:32
WORDPRESS: featured image url
<?php if (has_post_thumbnail( $post->ID ) ): ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
<div id="custom-bg" style="background-image: url('<?php echo $image[0]; ?>')">
</div>
<?php endif; ?>
@raaar
raaar / php
Created August 14, 2012 11:40
WORDPRESS: remove <p> from uploaded images in post
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
add_filter('the_content', 'filter_ptags_on_images');
@raaar
raaar / php
Created August 18, 2012 00:02
WORDPRESS: responsive captions filter
add_filter( 'img_caption_shortcode', 'dap_responsive_img_caption_filter', 10, 3 );
function dap_responsive_img_caption_filter( $val, $attr, $content = null ) {
extract(shortcode_atts( array(
'id' => '',
'align' => '',
'width' => '',
'caption' => ''
),
$attr));
@raaar
raaar / php
Created August 19, 2012 21:01
WORDPRESS: list items in taxonomy from the whole site
<?php
//list terms in a given taxonomy using wp_list_categories (also useful as a widget if using a PHP Code plugin)
$taxonomy = 'genre';
$orderby = 'name';
$show_count = 0; // 1 for yes, 0 for no
$pad_counts = 0; // 1 for yes, 0 for no
$hierarchical = 1; // 1 for yes, 0 for no
$title = '';
@raaar
raaar / gist:3533567
Created August 30, 2012 17:07
WORDPRESS - pretty permalinks
/%category%/%postname%/
@raaar
raaar / php
Created August 30, 2012 22:28
WORDPRESS - Grab custom Field - Meta Custom
<?php $values = get_post_custom_values('Brewery'); ?>
<?php
if ( $values ) { ?>
<div class="custom-field">
<?php $key="Brewery";?>
<p><?php echo get_post_meta($post->ID, $key, true); ?></p>
</div>