I found this useful to increase the WordPress upload size limit. Not only will it increase the upload size limit, but it increases the memory restriction for resizing images too. So if you have a large image for which WordPress can’t create the thumbnail for, try this.
Place this code in /wp-admin/php.ini:
memory_limit = 256M upload_max_filesize = "64M" post_max_size = "64M" max_execution_time = "500" max_input_time = "500"
function is_in_cats($catID){
global $post;
foreach((get_the_category($post->ID)) as $cat) {
if( in_array($catID, get_category_array()) ){
return true;
}
}
return false;
}
Usage:
if(is_in_cats(5)){
echo "Post is in category 5";
} else {
echo "Post is not in category 5";
}
function custom_excerpt($length){
global $post;
$content = strip_tags($post->post_content);
preg_match('/^\s*+(?:\S++\s*+){1,'.$length.'}/', $content, $matches);
echo "<p>" . $matches[0] . "</p>";
}
Use it like this, changing the argument for the number of words you want:
custom_excerpt(20);
5 April 2011
Wordpress functionsMoving your WordPress website to a different server? You need to do the following:
With this done, your new website will probably show a 404 error page, and your image URLs and hyperlinks will still reference the old server address. What to do? You need to run these 4 SQL commands on your new database, replacing www.olddomain.com and www.newdomain.com in each instance:
UPDATE wp_options SET option_value = replace(option_value, 'http://www.olddomain.com','http://www.newdomain.com');
UPDATE wp_posts SET guid = replace(guid, 'http://www.olddomain.com','http://www.newdomain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.olddomain.com','http://www.newdomain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.olddomain.com','http://www.newdomain.com');
Put this in functions.php:
function the_excluded_category($excludedcats = array()){
$count = 0;
$categories = get_the_category();
foreach($categories as $category) {
$count++;
if ( !in_array($category->cat_ID, $excludedcats) ) {
echo '<a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "Cortos de %s" ), $category->name ) . '" ' . '>' . $category->name.'</a>';
if( $count != count($categories)-1 ){
echo ", ";
}
}
}
}
Usage:
Call it in your template file like this:
<?php the_excluded_category(array(1,328,338,339)); ?>
Insert this in your theme’s functions.php file:
function create_id_list($pages, $explode = false){
$pagelist = array();
foreach ($pages as $pagg){
$pagelist[] = $pagg->ID;
}
if($explode == true){
return implode(",", $pagelist);
} else {
return $pagelist;
}
}
Usage:
$mypages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc');
$idlist = create_id_list($mypages); // Returns an array
$idlistcsv = create_id_list($mypages, true); // Returns a comma-separated list
Insert this in your functions.php file:
// Returns an array of the current post's categories
function get_category_array(){
global $post;
$cat_array = array();
foreach((get_the_category()) as $category) {
$cat_array .= $category->cat_ID;
}
return $cat_array;
}
Add this to whichever of your theme’s template files you want to redirect:
// Redirect to first child page. Place this in the loop.
function redirect_to_first_child(){
$pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order");
if ($pagekids) {
$firstchild = $pagekids[0];
wp_redirect(get_permalink($firstchild->ID));
}
}
Add this to your functions.php file:
function has_children(){
global $post;
if( ($post->post_parent == 0 && wp_list_pages('title_li=&child_of='.$post->ID.'&echo=0'))
||
($post->post_parent > 0 && wp_list_pages('title_li=&child_of='.$post->post_parent.'&echo=0'))
){
return true;
} else {
return false;
}
}
Add this to your functions.php file:
function new_excerpt_more($more){
global $post;
return " [...]<br/> <a href='".get_permalink() ."#post-".$post->ID."' class='read-more'>Read More ></a>";
}
add_filter('excerpt_more', 'new_excerpt_more');
You can change the return code to change the text added to the link, or change this for an image for instance.