Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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
Wordpress post页面未显示库中的所有图像_Wordpress_Gallery - Fatal编程技术网

Wordpress post页面未显示库中的所有图像

Wordpress post页面未显示库中的所有图像,wordpress,gallery,Wordpress,Gallery,我希望有人能帮上忙,因为这会害死我。我和别人一起工作,有很多麻烦,我是wordpress的新手 我想让帖子在页面顶部显示图库中的第一个图像,然后在下面显示第二个图像(在一些文本内容旁边),然后在下面显示图库中所有剩余的图像。出于某种原因,它目前将画廊中的最后两张图片排除在外,就好像它们被故意排除在外一样。非常感谢你的帮助,我很感激 这是当前代码: <?php get_header(); if (have_posts()) { while (have_posts()) { the

我希望有人能帮上忙,因为这会害死我。我和别人一起工作,有很多麻烦,我是wordpress的新手

我想让帖子在页面顶部显示图库中的第一个图像,然后在下面显示第二个图像(在一些文本内容旁边),然后在下面显示图库中所有剩余的图像。出于某种原因,它目前将画廊中的最后两张图片排除在外,就好像它们被故意排除在外一样。非常感谢你的帮助,我很感激

这是当前代码:

<?php

get_header();

if (have_posts()) {
while (have_posts()) {
    the_post();
    $images = GetPostImages(); // Get Post Images
    $tags = GetPostTags(); // Get Post Tags String
    ?>                    
<div class="project">

<img src="<?php echo $images[1]->guid; ?>" class="large" width="1000" height="700" />

<div class="projectdesc">  
    <h1><?php the_title(); ?></h1>
        <p class="tags"><?php echo $tags; ?></p>

    <?php 
the_content(); ?>

</div>

<img src="<?php echo $images[2]->guid; ?>" class="right" width="600" height="400" />

 <?php
        // Additional Project Images
        for ($i = 3; $i < count($images); $i++) {
            ?>
            <img src="<?php echo $images[$i]->guid; ?>" class="large" width="1000"/>        
            <?php
        }
        ?> 

    </div>

    <?php
}
}

get_footer();
?>`

}

使用wp\u get\u attachment\u image\u src()获取图像源

$attr = wp_get_attachment_image_src(int $id,string $size); //where $id is image post id

$width  =  $attr[1];
$height =  $attr[2];
$src    =  $attr[0]; //the source

echo sprintf('<img src="%s" alt="" height="%s" width="%s"/>',$src,$height,$width);

那么,我是否要用您提供的示例替换旧代码?首先引用大小图像的人会发生什么情况?实际上,在小图像和它下面的所有其他图像之间有一些内容,我在代码示例中遗漏了这些内容以保持简单。对不起,我对wordpress还不是很有经验。还有,有没有更简单的方法。例如,我可以看到第二个图像可以使用:$images[2]引用。有没有办法将其设置为一个范围?i、 e..$images[2-100]为我提供了该页面的完整脚本,以及您希望为我实现的进一步帮助的示例OK非常感谢@user622018。我已经用完整的代码编辑了我的原始问题。
$attr = wp_get_attachment_image_src(int $id,string $size); //where $id is image post id

$width  =  $attr[1];
$height =  $attr[2];
$src    =  $attr[0]; //the source

echo sprintf('<img src="%s" alt="" height="%s" width="%s"/>',$src,$height,$width);
function setup_images(){

//Register Image dimensions
add_image_size( 'large',1000,700,true); //'large' will be the string used in $size
add_image_size( 'med',600,400,true);  //or 'med'
}
add_action('after_setup_theme','setup_images'); //hook that function up in the right place