Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取Wordpress附件图像url_Php_Wordpress - Fatal编程技术网

Php 获取Wordpress附件图像url

Php 获取Wordpress附件图像url,php,wordpress,Php,Wordpress,我正试图显示所有附在wordpress帖子上的图像,并将图像链接到图像源,以便在灯箱中打开它。我正在使用以下代码: if (have_posts()) { while (have_posts()) { the_post(); $args = array( 'orderby' => 'title', 'order' => 'ASC', 'post_type'

我正试图显示所有附在wordpress帖子上的图像,并将图像链接到图像源,以便在灯箱中打开它。我正在使用以下代码:

if (have_posts())
{
    while (have_posts())
    {
        the_post();    
        $args = array(
            'orderby' => 'title',
            'order' => 'ASC',
            'post_type' => 'attachment',
            'numberposts' => -1,
            'post_status' => null,
            'post_parent' => $post->ID,
            'exclude' => get_post_thumbnail_id()
        );
        $attachments = get_posts( $args );
        if ($attachments)
        {
            foreach ($attachments as $attachment)
            {
                ?>
                <div id="image">
                    <a rel="lightbox" href="<?php /* ??? */ ?>">
                    <?php echo wp_get_attachment_image ($attachment->ID, 'full'); ?>
                    </a>
                </div>
                <?php
            }
        }
    }
}
if(have_posts())
{
while(have_posts())
{
_post();
$args=数组(
'orderby'=>'title',
“订单”=>“ASC”,
“post_类型”=>“附件”,
“numberposts”=>-1,
“post_状态”=>null,
'post_parent'=>$post->ID,
'exclude'=>get\u post\u缩略图\u id()
);
$attachments=get_posts($args);
若有($附件)
{
foreach($attachments作为$attachment)
{
?>

使用
wp\u get\u attachment\u image\u src

这:

应返回包含以下元素的数组

[0] => url
[1] => width
[2] => height
[3] => boolean: true if $url is a resized image, false if it is the original or if no image is available.

使用
wp\u get\u attachment\u image\u src

这:

应返回包含以下元素的数组

[0] => url
[1] => width
[2] => height
[3] => boolean: true if $url is a resized image, false if it is the original or if no image is available.

如果您只想链接到原始完整图像,最好只使用“wp\u get\u attachment\u url”——


wp_get_attachment_image_src函数将运行您不需要的代码,并返回您不需要的额外细节,从而降低代码的效率。

如果您只想链接到原始完整图像,最好只使用“wp_get_attachment_url”——

wp_get_attachment_image_src函数将运行您不需要的代码,并返回您不需要的额外细节,从而降低代码的效率