【问题标题】:How can i get gallery images from gallery Shortcode in wordpress?如何从 wordpress 中的画廊简码中获取画廊图像?
【发布时间】:2011-11-22 06:12:01
【问题描述】:

我有包含内容和图片库的 wordpress 页面。当我 print_r 我的内容时,它显示如下

    stdClass Object
(
    [ID] => 4558
    [post_author] => 1
    [post_date] => 2011-09-22 05:34:44
    [post_date_gmt] => 2011-09-22 05:34:44
    [post_content] => 

Nayer has pursued her passion for art since childhood. 
She believes that art should have a positive influence in the world and on our life experiences. 
She studied in Persia at Tehran University and at California State University, Los Angeles.



    [gallery link="file" columns="2"]

        [post_title] => About the Water Artist
        [post_excerpt] => 
        [post_status] => publish
        [comment_status] => open
        [ping_status] => open
        [post_password] => 
        [post_name] => about-the-water-artist
        [to_ping] => 
        [pinged] => 
        [post_modified] => 2011-11-22 04:59:58
        [post_modified_gmt] => 2011-11-22 04:59:58
        [post_content_filtered] => 
        [post_parent] => 0
        [guid] => http://nagu.wordpress.net/?page_id=4558
        [menu_order] => 0
        [post_type] => page
        [post_mime_type] => 
        [comment_count] => 0
        [ancestors] => Array
            (
            )

        [filter] => raw
    )

从 [post_content] 中的上述响应中,我找到了图库短代码 [gallery link="file" columns="2"]。图片未显示。

是否有可能单独使用该短代码从帖子内容中提取图片网址?

【问题讨论】:

  • 我也有兴趣找到这个
  • @Jordan Rynard 我在下面发布了答案。它对我来说很好。

标签: wordpress image-gallery


【解决方案1】:

我使用下面的代码从画廊简码中提取图像,它正在工作。

<?php   
global $post;
global $wp_query;
    $currentPageCatId = get_cat_ID( "pagename" );
        $NewsCatPostsArray = query_posts( 'cat='.$currentPageCatId);

         $current_news_postId = $NewsCatPostsArray[$i]->ID;
                                        $current_news_postUrl = get_permalink($current_news_postId);
                                        $query_images_args = array('post_type' => 'attachment', 'post_mime_type' =>'image', 'post_status' => 'inherit', 'posts_per_page' => -1,'post_parent' => $current_news_postId);

                                        $query_images = new WP_Query($query_images_args);
                                        $images = array();
                                        foreach ( $query_images->posts as $image) {
                                            $images[]= $image->guid;
                                        }
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-23
    • 1970-01-01
    相关资源
    最近更新 更多