我想使用<?php if (statement): ?>
,<?php else if (statement): ?>
和<?php else: ?>
lines 使我的代码更具可读性。我不太确定这是否是正确的语法。我也想知道我是否可以在这些 if 块中使用 php 代码。这就是我正在使用的:
<?php $blogexcerpt = $Blog->create_excerpt(html_entity_decode($post->content), 0, 250); ?>
<!-- if the blogexcerpt contains less than 5 non-white spaces assume there is media and use the "View Media" tag -->
<?php if ( strlen(preg_replace( '/\s+/', ' ', $blogexcerpt)) < 5 ): ?>
<h5 style="margin:0px;"><a href="<?php echo $Blog->get_blog_url('post').$post->slug; ?>" class="blog_post_link">View Media…</a></h5>
<!-- else if the blog post is less than excerpt length post entire -->
<?php else if ( strlen($Blog->create_excerpt(html_entity_decode($post->content), 0, 255)) < 250 ): ?>
<?php echo $blogexcerpt; ?>
<h5 style="margin:0px;"><a href="<?php echo $Blog->get_blog_url('post').$post->slug; ?>" class="blog_post_link">View post</a></h5>
<!-- else show excerpt -->
<?php else: ?>
<?php echo $blogexcerpt; ?><span style="display: inline;">…</span>
<h5 style="margin:0px;"><a href="<?php echo $Blog->get_blog_url('post').$post->slug; ?>" class="blog_post_link">Read more…</a></h5>
<?php endif>