Php Wordpress WP_查询
由于某些原因,如果我传入$attachment\u id,我就无法显示附件。如果我传入一个实际值,比如187,它就可以工作 我正在使用WpAlchemy和自定义图像大小插件Php Wordpress WP_查询,php,wordpress,custom-post-type,Php,Wordpress,Custom Post Type,由于某些原因,如果我传入$attachment\u id,我就无法显示附件。如果我传入一个实际值,比如187,它就可以工作 我正在使用WpAlchemy和自定义图像大小插件 <section id="new"> <?php $myquery = new WP_Query(array('post_type' => array('post', 'website_gallery'),'showposts' => '2')); while ($myquery->h
<section id="new">
<?php $myquery = new WP_Query(array('post_type' => array('post', 'website_gallery'),'showposts' => '2'));
while ($myquery->have_posts()) : $myquery->the_post();
global $custom_metabox;
?>
<div class="latest hentry">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php $website_gallery->the_meta(); ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<img src="<?php $website_gallery->the_value('galleryimage');?>" alt="<?php the_title(); ?>">
</a>
<?php echo wp_get_attachment_image($attachment_id, '220x80'); ?>
</div>
<?php endwhile; wp_reset_query(); ?>
</section>
我认为您可以使用
get\u post()
函数获取附件idget_post()
需要一个数组作为其参数,该数组可以是这样的:
$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => $post->ID );
由于您需要附件,请确保您的“post\u type”=>“attachment”
然后,您可以执行以下操作:
$attachments = get_post( $args );
if( $attachments ) {
foreach( $attachments as $attachment ) {
echo wp_get_attachment_image( $attachment->ID, '220x80' );
}
}
根据需要调整代码。希望它对你有用
签出:您在哪里设置$attachment\u id?感谢您之前的设置,但这不起作用。我想这是我用来调整图像大小的插件。