wordpress - 我如何从 WordPress 中的画廊简码获取画廊图像?

标签 wordpress image-gallery

我有包含内容和图片库的 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]中的上述回复中,我找到了画廊短代码[画廊链接="file"列=“2”]。图像未显示。

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

最佳答案

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

<?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;
                                        }
?>

关于wordpress - 我如何从 WordPress 中的画廊简码获取画廊图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8222726/

上一篇:php - Mopub 集成

下一篇:UML-RT 建模工具

相关文章:

php - 在本地主机上运行 Wordpress,希望使其在 Windows Server 2003 上运行

javascript - 在 Wordpress 中使用 Avada 主题将 HTML 和 JavaScript 添加到页面

wordpress - 强制非 WWW 但强制 https 跨所有 wordpress 和整个域

php - 使用 Twitter Bootstrap 创建图片库

具有不同图像大小的 JavaScript 和 Bootstrap 图像库

css - Bootstrap 3 CSS 图像标题覆盖

php - Wordpress:图形不只出现在单个帖子中

php - WooCommerce 在列表中添加类名

javascript - 当页面包含指向一张图像的多个链接时,fancyBox 会复制缩略图辅助图像

java - 如何在点击android时全屏显示图像?