檢查WordPress使用容量
若你想在控制台顯示目前網站空間使用情形
若你想在控制台顯示目前網站空間使用情形
WordPress 某些主題在首頁只會顯示"特色圖片",你可以用以下兩種方式直接顯示文章的第一張照片
方式1:
//抓取文章第一張圖片
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "/images/default.jpg";
}
return $first_img;
}
<p><img src="<?php echo catch_that_image() ?>"></p><!-- 顯示第一張圖片 -->
方式2:
複製下面的代碼到 functions.php 中
//Automatically Set the Featured Image in WordPress
function autoset_featured() {
global $post;
$already_has_thumb = has_post_thumbnail($post->ID);
if (!$already_has_thumb) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment_id);
}
}
}
} //end function
add_action('the_post', 'autoset_featured');
add_action('save_post', 'autoset_featured');
add_action('draft_to_publish', 'autoset_featured');
add_action('new_to_publish', 'autoset_featured');
add_action('pending_to_publish', 'autoset_featured');
add_action('future_to_publish', 'autoset_featured');