Useful:
function get_post_image($size = 'thumbnail') {
global $post;
$photos = get_children( array('post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID') );
if ($photos) {
$photo = array_shift($photos);
return wp_get_attachment_image($photo->ID, $size);
}
return false;
}
Continue Reading →
Little trick: to limit the default WordPress the_excerpt(); for all posts (55 characters), include this on your functions.php:
Continue Reading →
This function is used to get the_permalink() of a certain page using it’s ID (outside the loop). To use it within a theme, just:
<?php getPageLink(ID); ?>
function getPageLink($pageId){
if(!is_numeric($pageId)) {
return;
}
global $wpdb;
$sql_query = 'SELECT DISTINCT * FROM ' . $wpdb->posts . ' WHERE ' . $wpdb->posts . '.ID=' . $pageId;
$posts = $wpdb->get_results($sql_query);
if(!empty($posts)) {
foreach($posts as $post) {
return nl2br($post->guid);
}
}
}
This function is used to get the title(); of a certain page using it’s ID (outside the loop). To use it within a theme, just:
<?php getPageTitle(ID); ?>
function getPageTitle($pageId){
if(!is_numeric($pageId)) {
return;
}
global $wpdb;
$sql_query = 'SELECT DISTINCT * FROM ' . $wpdb->posts . ' WHERE ' . $wpdb->posts . '.ID=' . $pageId;
$posts = $wpdb->get_results($sql_query);
if(!empty($posts)) {
foreach($posts as $post) {
return nl2br($post->post_title);
}
}
}
This function is used to construct breadcrumbs of pages, posts and archives within WordPress. Put this on functions.php inside yout theme and call anywhere you need (single.php, page.php) using:
Continue Reading →