2013-01-11 1 views
2

방금 ​​Wordpress 3.5로 업데이트되었지만 코드의 일부가 손상되었습니다 : AJAX를 통해 갤러리와 함께 특정 게시물을로드하는 PHP 파일이 있습니다. 게시물은 [갤러리] 단축 코드가 포함되어Wordpress 3.5 : 이미지가 포함 된 갤러리가 작동하지 않습니다.

<?php 

// Include WordPress 
define('WP_USE_THEMES', false); 
require('../../../../wp-load.php'); 

$id = $_POST['id']; 

// query post with this identifier 
query_posts('meta_key=identifier&meta_value='.$id); 
if (have_posts()) : 
while (have_posts()) : the_post(); 

    // add content 
    $content = apply_filters('the_content', get_the_content()); 
    echo '<div class="content-inner">'.$content.'</div>'; 
endwhile; 
endif; 
?> 

: 같은

코드가 보인다.

remove_shortcode('gallery'); 
add_shortcode('gallery', 'parse_gallery_shortcode'); 

function parse_gallery_shortcode($atts) { 

    global $post; 

    extract(shortcode_atts(array(
     'orderby' => 'menu_order ASC, ID ASC', 
     'id' => $post->ID, 
     'itemtag' => 'dl', 
     'icontag' => 'dt', 
     'captiontag' => 'dd', 
     'columns' => 3, 
     'size' => 'full', 
     'link' => 'file' 
    ), $atts)); 

    $args = array(
     'post_type' => 'attachment', 
     'post_parent' => $id, 
     'numberposts' => -1, 
     'orderby' => $orderby 
     ); 

    $images = get_posts($args); 
    print_r($images); 
} 

이 아약스로드 사람과 내 사이트의 다른 모든 갤러리와 함께 작동하지만,하지 :이 코드를 사용하여 내 자신의 워드 프레스 갤러리를 구축했습니다. 그리고 그것은 Wordpress 3.4와 함께 작업했습니다.

간과 한 Wordpress 3.5의 변경 사항이 있습니까?

답변

2

나는 그것을 알아 냈다. 이미 미디어 라이브러리에 업로드 된 이미지가있는 갤러리를 사용하는 경우 갤러리 단축 번호는 [gallery ids=1,2,3]인데, 그 의미는 이미지가 갤러리에만 연결 (및 연결되지 않음) 그래서 post_type=attachment이 작동하지 않습니다.

는 지금은 이미지 ID를 얻기 위해 정규 표현식을 사용하고 있습니다 :

$post_content = $post->post_content; 
preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids); 
$array_id = explode(",", $ids[1]); 
1

그것은 모든 galleries 또는 단일 gallery$post->IDget_post_galleries()를 사용하여 당겨하는 것이 가능합니다. 각 갤러리에는 이미지 ID 목록이 ids이고 image urls의 목록은 src입니다. 갤러리 개체는 근본적으로 짧은 코드 인수이므로 해당 개체에도 액세스 할 수 있습니다.

if ($galleries = get_post_galleries($post->ID, false)) { 

    $defaults = array (
     'orderby' => 'menu_order ASC, ID ASC', 
     'id'   => $post->ID, 
     'itemtag' => 'dl', 
     'icontag' => 'dt', 
     'captiontag' => 'dd', 
     'columns' => 3, 
     'size'  => 'full', 
     'link'  => 'file', 
     'ids'  => "", 
     'src'  => array(), 
    ); 

    foreach ($galleries as $gallery) { 

     // defaults 
     $args = wp_parse_args($gallery, $defaults); 

     // image ids 
     $args[ 'ids' ] = explode(',', $args[ 'ids' ]); 

     // image urls 
     $images = $args[ 'src' ]; 
    } 
}