<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显示一篇博客文章的摘录。它在我的头版
答案 0 :(得分:0)
了解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;?>
答案 1 :(得分:0)
如果您想要显示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>