If you see this error either suddenly (no specific task was done to cause the error) or frequently, try deactivating all plugins to rule-out a plugin-specific issue and try switching themes to rule-out a theme-specific issue. Specific fixes: 1. If you’re using WordPress 2.9.2 or lower, try adding define(‘WP_MEMORY_LIMIT’, ‘256M’); to your wp-config.php file. If… Continue reading Fix a Fatal Memory Error
Remove weird characters from a database
UPDATE wp_posts SET post_content = REPLACE(post_content, ‘“’, ‘“’); UPDATE wp_posts SET post_content = REPLACE(post_content, ‘†‘, ‘”’); UPDATE wp_posts SET post_content = REPLACE(post_content, ‘’’, ‘’’); UPDATE wp_posts SET post_content = REPLACE(post_content, ‘‘’, ‘‘’); UPDATE wp_posts SET post_content = REPLACE(post_content, ‘—’, ‘–’); UPDATE wp_posts SET post_content = REPLACE(post_content, ‘–’, ‘—’); UPDATE wp_posts SET post_content = REPLACE(post_content,… Continue reading Remove weird characters from a database
Create Your Own Loop With WP_Query
<?php $recentPosts = new WP_Query(); $recentPosts->query(’showposts=5’); ?> <?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?> <!– do some stuff here –> <?php endwhile; ?> With Pagination: <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query(’showposts=5′.’&paged=’.$paged); ?> <!– do some stuff here –> <?php $wp_query = null; $wp_query = $temp; ?>
Improved Excerpt
function improved_trim_excerpt( $text ) { if ( ” == $text ) { $permalink = get_permalink(); // my addition $text = get_the_content( ” ); $text = strip_shortcodes( $text ); $text = apply_filters( ‘the_content’, $text ); $text = preg_replace( ‘@<script[^>]*?> . *?</script>@si’, ”, $text ); $text = str_replace( ‘]]>’, ‘]]>’, $text ); $text = strip_tags( $text, ‘<b><em><i><p><strong><sub><sup><a>’… Continue reading Improved Excerpt
Get the image plugin
Usage: <?php get_the_image( array( ‘default_image’ => ‘http://mysite.com/wp-content/uploads/example.jpg’ ) ); ?> Parameters: $defaults = array( ‘meta_key’ => array( ‘Thumbnail’, ‘thumbnail’ ), ‘post_id’ => $post->ID, ‘attachment’ => true, ‘the_post_thumbnail’ => true, ‘size’ => ‘thumbnail’, ‘default_image’ => false, ‘order_of_image’ => 1, ‘link_to_post’ => true, ‘image_class’ => false, ‘image_scan’ => false, ‘width’ => false, ‘height’ => false, ‘format’ =>… Continue reading Get the image plugin
Related posts
<?php //Gets category info global $wp_query; $cats = get_the_category(); $tempQuery = $wp_query; $currentId = $post->ID; //related category posts $catlist = ""; forEach( $cats as $c ) { if( $catlist != "" ) { $catlist .= ","; } $catlist .= $c->cat_ID; } $newQuery = "posts_per_page=6&orderby=rand&cat=" . $catlist; query_posts( $newQuery ); $categoryPosts = ""; $count =… Continue reading Related posts
Conditional Statements
<?php if ( ) { ?> <?php } else ( ) { ?> <?php } ?> Conditional Tags: is_page() is_single() is_category() is_author() is_home() Usage Examples: is_page(‘3’) is_page(‘About Us’’) is_page(‘about-us’) is_category(‘5’) is_category(‘Apples’) is_category(‘apples’) Example #1: Multiple conditions <?php if ( is_page(’Apples’) ) { ?> <img src="apples.gif" /> <?php } elseif ( is_page(’Oranges’)… Continue reading Conditional Statements
Random Post list
<ul> <?php $args = array( ‘numberposts’ => 5, ‘orderby’ => ‘rand’ ); $rand_posts = get_posts( $args ); foreach( $rand_posts as $post ) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>
List of Posts
Simple list: <ul> <?php global $post; $args = array( ‘numberposts’ => 5, ‘offset’=> 1, ‘category’ => 1 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul> All post data: <?php $args = array( ‘numberposts’ => 3 ); $lastposts = get_posts(… Continue reading List of Posts
Display tags in 3 columns
<?php $tags = get_terms(’post_tag’); $groups = array(’name__like’ => "a", ‘order’ => ‘ASC’); $tags_count = count($tags); $count = intval( $tags->count ); $percolumn = ceil($tags_count / 3); for ($i = 0;$i < $tags_count;$i++): if ($i < $percolumn): $tag_left .= ‘ <li><a href="’. get_tag_link($tags[$i]->term_id) . ‘"rel="tag">’ . $tags[$i]->name .’ (‘ . $tags[$i]->count . ‘)</a></li> ‘ . "\n";… Continue reading Display tags in 3 columns
Exclude category from feed
Add to functions.php function myFeedExcluder($query) { if ($query->is_feed) { $query->set(’cat’,’-6’); } return $query; } add_filter(’pre_get_posts’,’myFeedExcluder’);
Caption
.wp-caption { text-align: center; border: 1px solid #625B54; margin: 15px 10px 10px; padding: 5px 1px 0; } .wp-caption img { border: 0 none; margin-bottom: 5px; padding: 0; } .wp-caption p.wp-caption-text { font-size: 85%; line-height: 17px; margin: 0; padding: 0 4px 4px; }
CSS3 Border Radius
-webkit-border-radius: 5px 5px; -moz-border-radius: 5px 5px; border-radius: 5px 5px;
CSS3 Hover Opacity
a img.feed { border: none; opacity: 1.0; -ms-filter: "progid:DXImageTransform.Microsoft. Alpha(Opacity=100)"; filter: alpha(opacity = 100); -webkit-transition: opacity 0.2s ease-in-out; -moz-transition: opacity 0.2s ease-in-out; -o-transition: opacity 0.2s ease-in-out; transition: opacity 0.2s ease-in-out; } a:hover img.feed, a:focus img.feed { opacity: 0.70; -ms-filter: "progid:DXImageTransform.Microsoft. Alpha(Opacity=70)"; filter: alpha(opacity = 70); }
Generate current year
<? echo date(’Y’) ;?>
Exclude categories from index loop
<?php $posts=query_posts($query_string . ‘&cat=-6’); if (have_posts()) : while (have_posts()) : the_post(); ?>
Custom Taxonomies
Add to functions.php: add_action( ‘init’, ‘create_my_taxonomies’, 0 ); function create_my_taxonomies() { register_taxonomy( ‘ingredients’, ‘post’, array( ‘hierarchical’ => false, ‘label’ => ‘Ingredients’, ‘query_var’ => true, ‘rewrite’ => true ) ); }
Thumbnails
Add to functions.php: add_theme_support( ‘post-thumbnails’ ); Add to theme: <?php echo get_the_post_thumbnail($page->ID, ‘thumbnail’); ?>