Php 获取Wordpress附件图像url
我正试图显示所有附在wordpress帖子上的图像,并将图像链接到图像源,以便在灯箱中打开它。我正在使用以下代码:Php 获取Wordpress附件图像url,php,wordpress,Php,Wordpress,我正试图显示所有附在wordpress帖子上的图像,并将图像链接到图像源,以便在灯箱中打开它。我正在使用以下代码: if (have_posts()) { while (have_posts()) { the_post(); $args = array( 'orderby' => 'title', 'order' => 'ASC', 'post_type'
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函数将运行您不需要的代码,并返回您不需要的额外细节,从而降低代码的效率