是否可以通过编程方式将图像添加到帖子中?我正在自定义模板(我的第一个)工作,我需要以特定的方式显示添加到帖子中的图像。(第一个图像作为标题图像,其余的img仅渲染为隐藏的img标记(将通过lightbox幻灯片显示)。
那么有没有这样的函数get_post_attachments(\'type\'=>\'image\')
我可以在循环中迭代谁的输出?
谢谢你的帮助
是否可以通过编程方式将图像添加到帖子中?我正在自定义模板(我的第一个)工作,我需要以特定的方式显示添加到帖子中的图像。(第一个图像作为标题图像,其余的img仅渲染为隐藏的img标记(将通过lightbox幻灯片显示)。
那么有没有这样的函数get_post_attachments(\'type\'=>\'image\')
我可以在循环中迭代谁的输出?
谢谢你的帮助
您可以使用get_posts()
(Codex ref for getting Post attachments).
<?php
$args = array(
\'post_type\' => \'attachment\',
\'post_mime_type\' => \'image\',
\'numberposts\' => -1,
\'post_status\' => null,
\'post_parent\' => $post->ID
);
$attached_images = get_posts( $args );
?>
这将获取附加到帖子的所有图像:
$args = array( \'post_type\' => \'attachment\', \'numberposts\' => -1, \'post_status\' => null, \'post_mime_type\' => \'image\', \'post_parent\' => $post->ID );
$attachments = get_posts( $args );
if ( $attachments ) {
foreach ( $attachments as $attachment ) {
...do stuff
}
}
有一个\'look at wp_get_attachment_image()’ 以及related functions, 这会让你开始的。我不知道如何使next\\u posts\\u link()在自定义WP\\u查询中工作。功能如下:function artists() { echo \'<div id=\"artists\">\'; $args = array( \'post_type\' => \'artist\', \'posts_per_page\' => 3, \'paged\' => get_query_var( \'page\' )); $loop = ne