添加最近的WordPress的帖子,精选的图片和摘录到HTML网站

问题描述:

我在几个论坛上研究过这个问题,并找到了最相关的答案:Add "Recent Posts" from a wordpress blog to a html static page添加最近的WordPress的帖子,精选的图片和摘录到HTML网站

我在寻找的是这个答案的扩展,这将允许我包含一个精选图像和post_excerpt。我已经搜索谷歌和这个论坛,无济于事。任何帮助,你可以提供将不胜感激。

我的目标是在从我的博客中抽取的HTML网站上包含一个RSS类型的源,该源位于我的网站的子目录中。

前面提到的PHP代码片段非常适合显示和链接到最新的帖子,但是,我想要在提要中显示精选的帖子图片和帖子摘录。

+0

感谢@丹洛的指导。 –

我找到了这个问题的答案,并希望与社区分享。希望别人会觉得它有用。

这里是我们使用以产生期望的效果的代码:

<section class="feed float-right"> 
    <h3>The Latest From Our Blog</h3> 
<?php 

include('blog/wp-load.php'); // Blog path 

$args = array('showposts' => 4); 

$the_query = new WP_Query($args); 

if($the_query->have_posts()): 

echo '<ul>'; 

while ($the_query->have_posts()) : $the_query->the_post(); 
    echo '<li><a href="'.get_the_permalink().'">'.get_the_post_thumbnail().' '.get_the_title().'</a> <p>'.get_the_excerpt($limit).'</p></li>'; 
endwhile; 

echo '</ul>'; 

endif; 

wp_reset_query(); 

?> 

</section> 

上面的代码被放置在要供给到显示HTML或PHP页面内。我们在这个实现中使用了部分,但divs也可以工作。该样式信息如下:

.feed { 
    width: 100%; 
    height: 350; 
    padding-bottom: 25px; 
} 

.feed h3 { 
    width: 90%; 
    margin: 20px auto; 
    padding-left: 35px; 
    font-family: 'Open Sans Condensed', sans-serif; 
    font-size: 23px; 
    font-weight: 400; 
    color: #fff; 
} 

.feed ul { 
    width: 90%; 
    margin: auto; 
    list-style: none; 
    font-family: 'Open Sans Condensed', sans-serif; 
    font-size: 15px; 
    font-weight: 400; 
    color: #fff; 
} 

.feed ul li { 
    position: relative; 
    float: left; 
    width: 45%; 
    margin-bottom: 30px!important; 
    margin-right: 5%; 
} 

.feed ul li a { 
    color: inherit; 
} 

.feed ul li p { 
    line-height: 18px; 
} 

.attachment-post-thumbnail { 
    position: relative; 
    float: left; 
    width: 140px!important; 
    height: 90px!important; 
    margin: auto 30px 30px auto; 
    border-radius: 4px; 
} 

您可以查看这里的最终结果是:https://www.moverspalmbeachcounty.com/