dtsps2098 2013-06-19 11:52
浏览 28
已采纳

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

I have managed to get three latest blog posts from wordpress into my external website but can only get them to sit in one div. My question is how do I get them to each sit in their own div. I need them to do this so that I can style each one individually (they each sit in a different coloured box and are positioned with Gridset).

Here is my code so far:

 <?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> 

I've been stuck on this for ages so any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • drtiwd06558 2013-06-19 14:18
    关注

    Assuming all the rest of your code works, you would just need to add a div container for each item inside of your while loop, as follows:

    <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>
    

    This would put each article inside a div. Each div has the class "blogArticle".

    Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求一下解题思路,完全不懂
  • ¥15 tensorflow
  • ¥15 densenet网络结构中,特征以cat方式复用后是怎么进行误差回传的
  • ¥15 STM32G471芯片spi设置了8位,总是发送16位
  • ¥15 R语言并行计算beta-NTI中tree文件的类型
  • ¥15 如何解读marsbar导出的ROI数据?
  • ¥20 求友友协助弄一下基于STC89C52单片机的声光控制灯原理图
  • ¥15 arduino双向交通灯设计
  • ¥15 有没有会粒子群算法的大能(○゜ε^○)求带不会出收敛图😭
  • ¥15 Matlab读取根元素出错