admin管理员组文章数量:1026989
I want to show a default thumbnail if a custom post not created yet. Here is my loop:
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<?php
if ( has_post_thumbnail( ) ) {
the_post_thumbnail( 'full', array( 'class' => 'mySlides' ) );
}
else {
echo '<img src="dummy-image-1-1.jpg" class="mySlides" height="350px"/>';
}
?>
<?php
endwhile;
wp_reset_postdata();
?>
If I created a post but not posted a thumbnail then show default thumbnail. But If I didn't create a post yet I want to show a default thumbnail. How to fix it?
I want to show a default thumbnail if a custom post not created yet. Here is my loop:
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<?php
if ( has_post_thumbnail( ) ) {
the_post_thumbnail( 'full', array( 'class' => 'mySlides' ) );
}
else {
echo '<img src="dummy-image-1-1.jpg" class="mySlides" height="350px"/>';
}
?>
<?php
endwhile;
wp_reset_postdata();
?>
If I created a post but not posted a thumbnail then show default thumbnail. But If I didn't create a post yet I want to show a default thumbnail. How to fix it?
Share Improve this question asked Mar 26, 2019 at 10:38 user155636user155636 2 |1 Answer
Reset to default 3Create "images" folder in current active theme the put "dummy-image-1-1.jpg" in that folder.
<?php
if ($the_query->have_posts() ) :
while ($the_query->have_posts()) : $the_query->the_post();
if ( has_post_thumbnail( ) ) {
the_post_thumbnail( 'full', array( 'class' => 'mySlides' ) );
} else {
?>
<img src="<?php echo get_template_directory_uri().'/images/dummy-image-1-1.jpg'; ?>" class="mySlides" height="350px"/>
<?php
}
endwhile;
else:
?>
<img src="<?php echo get_template_directory_uri().'/images/dummy-image-1-1.jpg'; ?>" class="mySlides" height="350px"/>
<?php
endif;
wp_reset_postdata();
?>
Use path according to the theme(parent or child)
get_stylesheet_directory_uri()
: url path to current Theme directoryget_template_directory_uri()
: url path to parent Theme directory
I want to show a default thumbnail if a custom post not created yet. Here is my loop:
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<?php
if ( has_post_thumbnail( ) ) {
the_post_thumbnail( 'full', array( 'class' => 'mySlides' ) );
}
else {
echo '<img src="dummy-image-1-1.jpg" class="mySlides" height="350px"/>';
}
?>
<?php
endwhile;
wp_reset_postdata();
?>
If I created a post but not posted a thumbnail then show default thumbnail. But If I didn't create a post yet I want to show a default thumbnail. How to fix it?
I want to show a default thumbnail if a custom post not created yet. Here is my loop:
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<?php
if ( has_post_thumbnail( ) ) {
the_post_thumbnail( 'full', array( 'class' => 'mySlides' ) );
}
else {
echo '<img src="dummy-image-1-1.jpg" class="mySlides" height="350px"/>';
}
?>
<?php
endwhile;
wp_reset_postdata();
?>
If I created a post but not posted a thumbnail then show default thumbnail. But If I didn't create a post yet I want to show a default thumbnail. How to fix it?
Share Improve this question asked Mar 26, 2019 at 10:38 user155636user155636 2- 1 I don't understand your question. "If I didn't create a post" -> if you didn't create a post, then there is nothing in the loop. How do you know whether something wasn't created yet? – kero Commented Mar 26, 2019 at 10:44
-
I already told it in my question. If I created a post but not upload image then it shows default image like
echo
else
But If I didn't created a post I want to show a default default Like if post not exists yet then show default – user155636 Commented Mar 26, 2019 at 10:59
1 Answer
Reset to default 3Create "images" folder in current active theme the put "dummy-image-1-1.jpg" in that folder.
<?php
if ($the_query->have_posts() ) :
while ($the_query->have_posts()) : $the_query->the_post();
if ( has_post_thumbnail( ) ) {
the_post_thumbnail( 'full', array( 'class' => 'mySlides' ) );
} else {
?>
<img src="<?php echo get_template_directory_uri().'/images/dummy-image-1-1.jpg'; ?>" class="mySlides" height="350px"/>
<?php
}
endwhile;
else:
?>
<img src="<?php echo get_template_directory_uri().'/images/dummy-image-1-1.jpg'; ?>" class="mySlides" height="350px"/>
<?php
endif;
wp_reset_postdata();
?>
Use path according to the theme(parent or child)
get_stylesheet_directory_uri()
: url path to current Theme directoryget_template_directory_uri()
: url path to parent Theme directory
本文标签: how to post default thumbnail if post not created yet
版权声明:本文标题:how to post default thumbnail if post not created yet 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745658018a2161713.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
echo
else
But If I didn't created a post I want to show a default default Like if post not exists yet then show default – user155636 Commented Mar 26, 2019 at 10:59