在静态HTML页面上显示最新的wordpress特色图像 [英] Display latest wordpress featured images on static HTML page
本文介绍了在静态HTML页面上显示最新的wordpress特色图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的网站的子文件夹(从html转换)和一个静态html主页上安装了一个wordpress博客页面。我想在主页上显示 3个最新帖子及其特色图片。下面的代码我可以显示最新的帖子文字,但我不知道如何显示帖子的特色图片。
进入wordpress自定义主题的index.php我在div中放置了精选照片:
< div id =blogphoto><?php the_post_thumbnail( ); ?>< / DIV>
这是静态html index.php页面上的代码,它正在提取最新帖子。任何人都可以帮助我获得这些帖子的精选图片吗?
< pre>< div id =wp-post>
<?php
$ args = array('numberposts'=> 1);
$ recent_posts = wp_get_recent_posts($ args);
foreach($ recent_posts as $ recent_post){
echo< h3>。$ recent_post ['post_title']。< / h3>< br>;
echo< span>。$ recent_post ['post_date']。< / span>< br>;
echo< p>。$ recent_post ['post_content']。< / p>< br>< br>;
}
?>
< / div>
< div id =wp-post2>
<?php
$ args = array('numberposts'=> 1,'offset'=> 1);
$ recent_posts = wp_get_recent_posts($ args);
foreach($ recent_posts as $ recent_post){
echo< span>。$ recent_post ['post_title']。< / span>< br>;
echo< p>。$ recent_post ['post_content']。< / p>< br>< br>;
}
?>
< / div>
< div id =wp-post3>
<?php
$ args = array('numberposts'=> 1,'offset'=> 2);
$ recent_posts = wp_get_recent_posts($ args);
foreach($ recent_posts as $ recent_post){
echo< span>。$ recent_post ['post_title']。< / span>< br>;
echo< p>。$ recent_post ['post_content']。< / p>< br>< br>;
}
?>
< / div>
我尝试过:
我尝试添加代码
<?php if(has_post_thumbnail($ post-> ID)):?>
<?php $ image = wp_get_attachment_image_src(get_post_thumbnail_id($ post-> ID),'single-post-thumbnail'); ?>
< div id =custom-bgstyle =background-image:url('<?php echo $ image [0];?>')>
< / div>
<?php endif; ?>
但是没有帮助
解决方案
args = array ( 'numberposts'=→1);
recent_posts = wp_get_recent_posts(
参数);
foreach(
I have a wordpress blog page installed in subfolder of my website(converted from html)and a static html home page. I would like to display 3 latest posts and its featured images on home page. With code below i can display latest posts text but i dont know how to show featured images of posts. Into index.php of a wordpress custom theme i placed featured photo inside a div: <div id="blogphoto"><?php the_post_thumbnail(); ?></div> This is the code on static html index.php page which is pulling out latest post. Can anyone help me to get featured images of these posts too? <pre><div id="wp-post"> <?php $args = array('numberposts'=>1); $recent_posts=wp_get_recent_posts($args); foreach( $recent_posts as $recent_post ){ echo "<h3>".$recent_post['post_title']."</h3> <br>"; echo "<span>".$recent_post['post_date']."</span> <br>"; echo "<p>".$recent_post['post_content']."</p><br><br>"; } ?> </div> <div id="wp-post2"> <?php $args = array('numberposts'=>1 , 'offset'=>1 ); $recent_posts=wp_get_recent_posts($args); foreach( $recent_posts as $recent_post ){ echo "<span>".$recent_post['post_title']."</span> <br>"; echo "<p>".$recent_post['post_content']."</p><br><br>"; } ?> </div> <div id="wp-post3"> <?php $args = array('numberposts'=>1 , 'offset'=>2 ); $recent_posts=wp_get_recent_posts($args); foreach( $recent_posts as $recent_post ){ echo "<span>".$recent_post['post_title']."</span> <br>"; echo "<p>".$recent_post['post_content']."</p><br><br>"; } ?> </div>
What I have tried:
I tried adding code
<?php if (has_post_thumbnail( $post->ID ) ): ?> <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?> <div id="custom-bg" style="background-image: url('<?php echo $image[0]; ?>')"> </div> <?php endif; ?>
but that didnt help
解决方案
args = array('numberposts'=>1);
recent_posts=wp_get_recent_posts(
args); foreach(
这篇关于在静态HTML页面上显示最新的wordpress特色图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文