帖子图像将存储在数据库wordpress中

问题描述 投票:0回答:4

我想知道帖子图像存储在数据库中的位置。我想获取各个帖子的图像网址。我在 wp_posts 表中搜索过,但找不到它。有人能帮我吗。

wordpress
4个回答
2
投票

WordPress 默认将图像存储在 wp-content/uploads 目录下,当前年份和月份作为子目录(yyyy/mm)。到目前为止的例子

wp-content/uploads/2013/09/img.png
.

图像包含在

blog_posts
表中
post_content
列中的 html 标签中。


2
投票

如果您尝试在页面视图中显示帖子附件,这是使用 WordPress 自己的功能来实现的一种方法。将获取所有帖子附件并以缩略图大小列出它们。

<?php    
$args = array(
    'post_type' => 'attachment',
    'numberposts' => -1,
    'post_parent' => $post->ID
);

$attachements = get_posts( $args );

if ( $attachements ):
?>

<!-- List all post images -->
<ul>         
<?php
    foreach ( $attachments as $attachment ) {
       echo '<li>';
       echo wp_get_attachment_image( $attachment->ID, 'thumbnail' );
       echo '</li>';
    }
?>
</ul>

<?php
endif;
?>

但是,如果只是想知道附件 URL 存储在哪一列,答案是

wp_posts > guid


1
投票

始终尝试使用WordPress提供的功能来满足要求。是的,图像(图像网址)作为附件存储在 wp_posts 表中。

<?php
$args = array( 
    'post_type' => 'attachment', 
    'post_mime_type' => 'image',
    'numberposts' => -1, 
    'post_status' => null, 
    'post_parent' => $post->ID 
); 
$attached_images = get_posts( $args );
?>

0
投票

特定帖子的所有图像(包括特色图像和其他图像)都存储在

posts
表中。您可以使用此 sql 查询找到所有图像

SELECT * FROM column_name_prefix_posts WHERE post_parent = post_id_which_images_link_you want

示例

SELECT * FROM wpmx_posts WHERE post_parent = 10

返回结果的引导是帖子图片。可能会注意到,您还会得到一些其他行,这些行没有任何意义,因此如果您只想要图像,那么您可以更新注释以仅获取

post_type
attachment
的行。

示例

 SELECT * FROM wpmx_posts WHERE post_parent = 10 AND post_type = 'attachment';

如果您只想从中获取特色图像,那么您可以首先从

__thumbnail_id
表中使用该
post_meta
搜索
post_id
,以获取
guid
列包含特色图像链接的 id。

示例

SELECT guid FROM wpmx_posts WHERE ID = ( SELECT meta_value FROM wpmx_postmeta WHERE post_id = {{post_id}} AND meta_key = '_thumbnail_id' );

只需将 {{post_id}} 替换为您想要特色图片的 post_id,它就会为您提供该帖子的特色图片

快乐编码!!!

© www.soinside.com 2019 - 2024. All rights reserved.