douqiang1851 2013-05-27 08:13
浏览 32
已采纳

如何从wordpress php中的博客页面获取图像? [重复]

This question already has an answer here:

I want to get number of images from blog page of wordpress..i have a code to get image nw but its giving me only images from individual post ..

Following is my code to get no of images in post ..

  $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;

  }

I want to get count of total images in active/published posts. i could get no of published posts in blog and also no of images in single posts ..But how to integrate it in order to get all total count???

</div>
  • 写回答

1条回答 默认 最新

  • dongming5444 2013-05-27 12:44
    关注

    You may try like this

    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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失