【发布时间】:2016-05-11 08:39:46
【问题描述】:
我的 wordpress 附件图片有类别和标签。我想在照片库中调用此信息。
好消息:在循环中调用时会显示正确的图像。坏消息:我无法调用图库中的特定数据。问题在下面全部大写:
<?php
$the_query = new WP_Query(array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'category_name' => 'architecture'
));
while ( $the_query->have_posts() ) :
$the_query->the_post();
?>
<figure class="gallery-photo" itemprop="associatedMedia" itemscope itemtype="http://schema.org/ImageObject" data-groups='["all", "PHP ATTACHMENT TAG"]'>
<a class="photo-link" href="<?php wp_get_attachment_image (); ?>" itemprop="contentUrl" data-size="CALL PHP ATTACHMENT IMAGE WIDTH & HEIGHT">
<img src="<?php wp_get_attachment_url ('full'); ?>" itemprop="thumbnail" />
<figcaption itemprop="caption description">PHP ATTACHMENT CAPTION</figcaption>
<div class="photo-title"><h2>PHP ATTACHMENT IMAGE TITLE</h2></div>
</a>
</figure>
<?php
endwhile;
wp_reset_postdata();
?>
我尝试了一些方法,但没有成功:
<?php $meta = wp_get_attachment_metadata($image->ID, true); echo '.$meta[width]."x".$meta[height].';?><?php $description = $post->post_content; echo $description;?><?php $image->post_title; ?>
这是插件,供参考:
// Custom media taxonomies
function add_categories_to_attachments() {
register_taxonomy_for_object_type( 'category', 'attachment' );
}
add_action( 'init' , 'add_categories_to_attachments' );
function add_tags_to_attachments() {
register_taxonomy_for_object_type( 'post_tag', 'attachment' );
}
add_action( 'init' , 'add_tags_to_attachments' );
这些自定义分类法对我来说是一个新概念,因此我正在努力学习如何绕过它们。提前感谢您的帮助!
【问题讨论】:
-
您是否尝试获取附加到帖子 ID(具有该 ID 的图像)的帖子元?
-
我想这就是我在 #1 中尝试过的,对吧?
-
我的意思是
get_post_meta():)
标签: wordpress tags attachment categories taxonomy