繁体   English   中英

如何将3个最新的Wordpress帖子嵌入到外部网站的单独div中?

[英]How to embed 3 latest Wordpress posts into separate divs in an external website?

我设法从wordpress获得了三篇最新的博客文章到我的外部网站,但是只能让它们放在一个div中。 我的问题是如何让他们各自坐在自己的div中。 我需要他们这样做,以便我可以分别为每个样式设置样式(它们分别位于不同的彩色框中,并与Gridset一起放置)。

到目前为止,这是我的代码:

 <?php 
  // Include Wordpress 
  define('WP_USE_THEMES', false); 
  require('wordpress/wp-load.php'); 
  query_posts('posts_per_page=3');
  ?>

<div id="blogFeed">
<?php while (have_posts()): the_post(); ?>
        <p class="subHeader"><?php the_date(); ?></p>
        <h1><?php the_title(); ?></h1>
        <?php the_content(); ?>
        <p class="moreNews darkGrey"><a href="<?php the_permalink(); ?>" target="_blank">Read more...</a></p>
        <?php endwhile; ?>
        </div> 

我已经坚持了很长时间,所以任何帮助将不胜感激。

假设所有其余代码都正常工作,则只需要为while循环内的每个项目添加一个div容器,如下所示:

<div id="blogFeed">
    <?php $divCounter = 0; ?>
    <?php while (have_posts()): the_post(); ?>
        <?php $divCounter += 1; ?>
        <div class="blogArticle blogCounter<?php echo $divCounter; ?>">
            <p class="subHeader"><?php the_date(); ?></p>
            <h1><?php the_title();?></h1>
            <?php the_content();?>
            <p class="moreNews darkGrey"><a href="<?php the_permalink(); ?>" target="_blank">Read more...</a></p>
        </div>
    <?php endwhile; ?>
</div>

这会将每篇文章放在div中。 每个div都有一个类“ blogArticle”。

希望这可以帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM