【问题标题】:add images to html in wordpress from 'Page'从“页面”将图像添加到 wordpress 中的 html
【发布时间】:2016-08-05 16:24:07
【问题描述】:

我正在 wordpress 上创建一个新页面并使用 php 代码添加图像。

这是我到目前为止的代码,它为我提供了数组中的 src url。但是我认为这给了我画廊中的所有图像。有没有办法只找到页面上的图像,然后将这些图像添加到页面中。请参阅下面的当前代码。

<?php

$query_images_args = array(
    'post_type'      => 'attachment',
    'post_mime_type' => 'image',
    'post_status'    => 'inherit',
    'posts_per_page' => - 1,
);

$query_images = new WP_Query( $query_images_args );

$images = array();
foreach ( $query_images->posts as $image ) {
    echo wp_get_attachment_url( $image->ID );
}

?>

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    试试这个

    echo "&lt;img src='".wp_get_attachment_url( $image-&gt;ID )."' /&gt;";

    【讨论】:

    • 这很好,但可以获取整个站点中的所有图像。我只是在该页面中寻找图像。有什么想法吗?
    • 您是否使用插件向页面添加图像?如果是,是什么?
    • 我没有使用插件,我正在尝试自己构建它!
    • 如何在页面中添加图片?您是添加额外的元字段并添加图片还是使用 wordpress 中默认可用的图片附件?
    • 只使用wordpress默认提供的图片附件
    猜你喜欢
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 2021-03-22
    • 2019-05-26
    • 2014-03-02
    • 1970-01-01
    相关资源
    最近更新 更多