尝试在每个div中获取三篇单独的博客文章


<section class="blog_posts clearfix">
    <h1>Latest Blog Posts</h1>
    <h2>We update our blog regularly with information that may be useful for your accident or injury case.</h2>

        <div class="blog_preview">
            <div class="blog_date">
                <h2 class="blog_month">Oct.</h2>
                <h1 class="blog_day">10</h1>
            </div>

            <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
            <p>Posted by <span>Gary</span> on Oct 10, 2013 in <span>Blog | 6 Comments</span></p>
            <?php if(have_posts()) : ?>
                <?php while(have_posts()) : the_post()?>
            <p><?php the_excerpt();?></p>
            <?php endwhile;?>
            <?php endif;?>
            <a class="read_more" href="http://www.heslinlaw.org/bicycle-riding-in-philadelphia/">Read More</a>
        </div>
    <div class="blog_preview">
        <div class="blog_date">
            <h2 class="blog_month">Sept.</h2>
            <h1 class="blog_day">22</h1>
        </div>

        <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <p>Posted by <span>Gary</span> on Sep 22, 2013 in <span>Blog | 2 Comments</span></p>
        <?php if(have_posts()) : ?>
            <?php while(have_posts()) : the_post()?>
        <p><?php the_excerpt();?></p>
        <?php endwhile;?>
        <?php endif;?>
        <a class="read_more" href="#">Read More</a>
    </div>

    <div class="blog_preview">
        <div class="blog_date">
            <h2 class="blog_month">July.</h2>
            <h1 class="blog_day">13</h1>
        </div>

        <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
        <p>Posted by <span>Gary</span> on July 13, 2013 in <span>Blog | 4 Comments</span></p>
        <?php query_posts('p=78'); ?>
        <?php if(have_posts()) : ?>
            <?php while(have_posts()) : the_post()?>
        <p><?php the_excerpt();?></p>
        <?php endwhile;?>
        <?php endif;?></p>
        <a class="read_more" href="#">Read More</a>
    </div>
<a href="#" class="blue_button">See Our Blog</a>
</section>
</div>

它将为永久链接显示"主页",并且摘录部分不显示正确的文本。

www.heslinlaw.org 是我试图转换为WordPress的网站。我正在尝试让每个div显示博客文章的摘录。 它在我的首页上

如果您希望显示 3 个最新帖子,请尝试以下操作:

<section class="blog_posts clearfix">
    <h1>Latest Blog Posts</h1>
    <h2>We update our blog regularly with information that may be useful for your accident or injury case.</h2>
<?php
$args = array( 'posts_per_page' => 3 );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post );
?>
<div class="blog_preview">
            <div class="blog_date">
                <h2 class="blog_month">Oct.</h2>
                <h1 class="blog_day">10</h1>
            </div>
            <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
            <p>Posted by <span>Gary</span> on Oct 10, 2013 in <span>Blog | 6 Comments</span></p>
            <p><?php the_excerpt();?></p>
            <a class="read_more" href="<?php the_permalink(); ?>">Read More</a>
        </div>
<?php
endforeach; 
wp_reset_postdata();
?>
<a href="#" class="blue_button">See Our Blog</a>
</section>

了解Wordpress如何生成帖子内容非常重要。 基本上,像"the_permalink(("和"the_title(("这样的函数从循环(http://codex.wordpress.org/The_Loop(中返回数据。 如果在循环外部调用这些函数,则会得到意外的结果。

    <?php if(have_posts()) : ?>
        <?php while(have_posts()) : the_post()?>
            <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
            <p>...Wordpress functions to display author, date, whatever</p>
            <p><?php the_excerpt();?></p>
            <a class="read_more" href="<?php the_permalink(); ?>">Read More</a>
        <?php endwhile;?>
    <?php endif;?>

相关内容

最新更新