我有两种不同的帖子类型,我想要有一段感情。作者可以列出一个业务(帖子类型 - "列表")和许多特别优惠(帖子类型 - " special_offers")。在每个特价商品页面中,我需要显示哪些商家提供特定商品。目前我正在使用此代码,并正确输出商家名称。我也需要商业标识(特色图片)
function get_author_business() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post_type' => 'listings', 'post__not_in' => array( $post->ID ), 'posts_per_page' => -1 ) );
foreach ( $authors_posts as $authors_post ) {
$output .= '<a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a>';
}
return $output;
}
答案 0 :(得分:1)
这可能会有所帮助(我假设您正在尝试在输出html中获取图像标记)
function get_author_business() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post_type' => 'listings', 'post__not_in' => array( $post->ID ), 'posts_per_page' => -1 ) );
foreach ( $authors_posts as $authors_post ) {
$business_img = wp_get_attachment_image_src( get_post_thumbnail_id( $authors_post->ID ), 'thumbnail' );
$output .= '<img src="'.$business_img[0].'"><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a>';
}
return $output;
}
答案 1 :(得分:0)
您可以使用以下代码:
<?php
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
$attachment_url=wp_get_attachment_image_src($post_thumbnail_id,'full');
/* full -- is image size */
?>
<img src="<?php echo $attachment_url; ?>">
希望这对你有用。