2013-05-27 61 views
0

我想从WordPress的博客页面获取图片数量..我有一个代码来获取图像NW,但它只给我从个人职位的图像..如何从wordpress php中的博客页面获取图片无?

以下是我的代码,以获取图像中没有图像..

$count_posts1 = wp_count_posts(); 
    $published_posts = $count_posts1->publish; 
    echo "<br />number of post -----".$published_posts; 
    $postimg = array(); 
    for ($j=0; $j<$published_posts; $j++) 
    { 
     $szPostContent = $post->post_content; 
     $szSearchPattern = '#(<img.*?>)#'; 
     $a=''; 
     $aPics=''; 
     preg_match_all($szSearchPattern, $szPostContent, $aPics); 
     $iNumberOfPics = count($aPics[$j]); 
     echo "<br />Number of pics on each post...............".$iNumberOfPics; 

    } 

我想要在活动/发布的帖子中获得总图像的数量。我可以不在博客发布的帖子,也没有在单个帖子中的图像..但如何整合它,以获得所有总数?

+1

你找谁检查没有图像的网页或内部后..your标题和查询都不同...... – sAnS

+0

@santanukumar我试图让计数图片在已发布的帖子中... –

+0

@santanukumar博客页面是指显示所有pos的页面。 –

回答

1

你可以试试这样

query_posts('post_status=publish'); 
while (have_posts()) : the_post(); 
$id = get_the_ID(); 
$total_attachments = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->prefix}posts WHERE post_type = 'attachment' AND post_parent=$id"); 
echo $total_attachments; 
endwhile; 
wp_reset_query(); 
+0

非常感谢@santanu。 –

+0

你欢迎.. :) – sAnS

相关问题