WordPress最近的新闻/帖子,带或不带特色图片
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WordPress最近的新闻/帖子,带或不带特色图片相关的知识,希望对你有一定的参考价值。
This will show a number of recent posts along with their associated featured image (thumbnail) if they have one. The template code asks for the 2 most recent posts with the custom post type of "news." Change the quantity and post type as needed. This also uses a custom excerpt generator, which isn't necessary except that this particular code references it.
<?php // custom excerpt generator. put into functions.php. function flexcerpt($excerpt = '', $excerpt_length = 50, $readmore = "Read more»", $tags = '<a>', $permalink = null) { global $post; $excerpt = strip_shortcodes($excerpt); if ($permalink === null) { $permalink = get_permalink(); } // $excerpt .= ' ... <a href="' . $permalink . '">' . $readmore . '</a>'; // return $excerpt; } else { //return $excerpt; } $excerpt .= '... <a href="' . $permalink . '">' . $readmore . '</a>'; return $excerpt; } ?> <!-- this goes into the template file. it is using a custom post type called "news" and can be changed to whatever is needed. --> <?php foreach ( $news as $post ): ?> <?php setup_postdata($post); ?> <div class="home-news-article <?php echo (has_post_thumbnail() ? 'with-thumbnail' : 'no-thumbnail') ?>"> <?php if (has_post_thumbnail()): ?> <div class="home-news-thumbnail"> <?php the_post_thumbnail( 'news-thumbnail' ); ?> </div><!--.home-news-thumbnail--> <?php endif ?> <div class="home-news-content"> <h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4> <?php echo flexcerpt( $post->post_excerpt ); ?> <?php else: ?> <?php echo flexcerpt( get_the_content() ); ?> <?php endif ?> </div><!--.home-news-content--> </div><!--.home-news-article--> <?php endforeach; ?>
以上是关于WordPress最近的新闻/帖子,带或不带特色图片的主要内容,如果未能解决你的问题,请参考以下文章