admin管理员组文章数量:1130349
I am currently trying to set the most recent post's featured image to be the background of my hero image. This is the code I'm using:
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
Problem is, it shows the featured image of the most recent most on the entire site. I'm trying to make it use the most recent featured image from a specific category (ID is 42). Could I do something like this:
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID;cat="45"), 'full' );?>
I am currently trying to set the most recent post's featured image to be the background of my hero image. This is the code I'm using:
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
Problem is, it shows the featured image of the most recent most on the entire site. I'm trying to make it use the most recent featured image from a specific category (ID is 42). Could I do something like this:
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID;cat="45"), 'full' );?>
Share
Improve this question
edited Nov 21, 2018 at 19:56
Owen
asked Nov 21, 2018 at 16:58
OwenOwen
33 bronze badges
1 Answer
Reset to default 0I am not sure where you are trying to do this but give something like this a try.
<?php
$category_id = 45;
query_posts('showposts=1&cat='.$category_id);
if (have_posts()) : while (have_posts()) : the_post();
$backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
endwhile; endif;
wp_reset_query();
?>
I am currently trying to set the most recent post's featured image to be the background of my hero image. This is the code I'm using:
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
Problem is, it shows the featured image of the most recent most on the entire site. I'm trying to make it use the most recent featured image from a specific category (ID is 42). Could I do something like this:
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID;cat="45"), 'full' );?>
I am currently trying to set the most recent post's featured image to be the background of my hero image. This is the code I'm using:
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );?>
Problem is, it shows the featured image of the most recent most on the entire site. I'm trying to make it use the most recent featured image from a specific category (ID is 42). Could I do something like this:
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID;cat="45"), 'full' );?>
Share
Improve this question
edited Nov 21, 2018 at 19:56
Owen
asked Nov 21, 2018 at 16:58
OwenOwen
33 bronze badges
1 Answer
Reset to default 0I am not sure where you are trying to do this but give something like this a try.
<?php
$category_id = 45;
query_posts('showposts=1&cat='.$category_id);
if (have_posts()) : while (have_posts()) : the_post();
$backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' );
endwhile; endif;
wp_reset_query();
?>
本文标签: categoriesHow to set featured image as background for a specific category
版权声明:本文标题:categories - How to set featured image as background for a specific category? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749161336a2325444.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论