Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

nhoullet on "Comment images to jQuery modal gallery"

$
0
0

I am making a plugin available for comments as well.The plugin grabs images and displays them in a modal gallery.
The code below is a function that grabs the images from posts and pages and sends the correct data to the jquery plugin.I added two "if" statements for comments but the plugin does not grab all those comment images.It transmits the correct image ID to each of them to the jquery plugin though.The same thing does not work for the "a data postid" attribute though.

function content($content)  {
    global $post;
    $children = &get_children(array('post_parent' => $post->ID, 'post_status' => 'inherit',
                                    'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC',
                                    'orderby' => 'menu_order ID'));
    if (empty($children)) {
     if (substr(get_post_mime_type($post->ID), 0, 5) == 'image') {
      $children = &get_posts(array('post_type' => 'attachment',
                                   'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID',
                                   'include' => $post->ID));
     }
    }
    $images = array();
    foreach ($children as $key => $val) {
     $images[$this->href(wp_get_attachment_link($key, 'full'))] =
     array('post_id' => $key, 'id' => $key, 'data' => $val,
           'permalink' => get_permalink($post->ID).'#'.$key);

     if ($comment){

      $children = &get_children(array('post_parent' => $comment_ID->ID, 'post_status' => 'inherit',
                                      'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC',
                                      'orderby' => 'menu_order ID'));

      $images = array();
      foreach ($children as $key => $val) {
       $images[$this->href(wp_get_attachment_link($key, 'full'))] =
       array('comment_ID' => $key, 'id' => $key, 'data' => $val,
             'permalink' => get_permalink($post->ID).'#'.$key);
      }
     }
    }

    $links = $this->links($content);
    $upload_dir = wp_upload_dir();
    $media = $upload_dir['baseurl'];
    $wpp_post = array();
    foreach ($links as $link) {
     if (is ($comment_text)){$wpp_post= $comment->content->images;}
     if (strpos($link, 'data-postid') === false) {
      $href = $this->href($link);
      if (!array_key_exists($href, $images) && $this->startswith($href, $media)) {
        $id = $this->get_attachment_id_from_src($href);
       if ($id != NULL) {
        $photos = &get_posts(array('post_type' => 'attachment',
                                   'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID',
                                   'include' => $id));
        if (count($photos) > 0) {
         $wpp_post[$href] = array('post_id' => $id, 'id' => $id, 'data' => $photos[0],
                                  'permalink' => get_permalink($id).'#0');
        }
       }
      } else if (array_key_exists($href, $images)) {
       $wpp_post[$href] = $images[$href];
      }
      if (array_key_exists($href, $wpp_post)) {
       $tmp = str_replace('<a ', '<a data-postid="wpp_post_'.$post->ID. '" data-imgid="'.$wpp_post[$href]['id'].'" ', $link);
       $content = str_replace($link, $tmp, $content);
      }
      if ($comment){$get_comment_meta($comment_ID);$BD=$comment_ID->ID;$tmp = str_replace('<a ', '<a data-postid="wpp_post_'.$BD. '" data-imgid="'.$wpp_post[$href]['id'].'" ', $link);
       $content = str_replace($link, $tmp, $content);}
     }
    }
    $this->append_json('wpp_post_'.$post->ID, $wpp_post);
    return $content;
   }

So to say my if($comment) thing does not work.The html output has the correct img ID for every image, but the post_id doesn't adapt to comments ( so the function could grab groups of images from every comment as well - like they were common posts ).Every thumbnail in comments opens the same,first image ever posted in the comments.The plugin should grab images and create jquery modal galleries for each comment that has an image or images.
The plugin does not rely on shortcodes and it must rely on the php code to find images.
Can you help ? thank you.


Viewing all articles
Browse latest Browse all 8245

Trending Articles