我在主页上的博客模板中使用摘录来显示 2 个带有阅读更多按钮的页面摘录和 1 个带有阅读更多按钮的最新博客文章。
下面是使用的代码
<?php
/*******PAGES SECTION CUSTOM*******/
$args=array(
'orderby' =>'parent',
'order' =>'asc',
'post_type' =>'page',
'post__in' => array(34,36),
);
$page_query = new WP_Query($args); ?>
<div class="pagesarea left">
<?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
<div class="section">
<h2 class="homeh2"><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
<?php the_excerpt(); ?>
<p class="readmore"><a href="<?php the_permalink();?>">Read More</a></p>
</div>
<?php endwhile; ?>
<?php
/*******LATEST NEWS SECTION*******/
$news_text = get_theme_option(tk_theme_name.'_home_news_text');
$news_per_page = get_theme_option(tk_theme_name.'_home_news_number');
$blog_id = get_option('id_blog_page');
$blog_url = get_permalink($blog_id);
if($hide_news == 'yes') {}else{
?>
<div class="section last">
<h2 class="homeh2"><a href="<?php the_permalink();?>"><?php _e('Latest News ', tk_theme_name) ?></a></h2>
<?php
$post_counter = 1;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 0;
$args=array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $news_per_page, 'ignore_sticky_posts'=> 1);
//The Query
query_posts($args);
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();
$post_day = get_the_time('d M');
$post_year = get_the_time('Y');
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'home-news');
$post_cats = get_the_category_list(',', $post->ID);
$cat_array = explode(',', $post_cats);
$number_of_cats = count($cat_array);
$cat_counter = 1;
$format = get_post_format();
?>
<p class="title"><?php echo $post_day?>
<?php echo $post_year?>
<?php the_title()?>
</p>
<?php the_excerpt(); ?>
<p class="readmore"><a href="<?php the_permalink();?>">Read More</a></p>
</div>
<?php $post_counter++;endwhile; ?>
<?php else: ?>
<?php endif; ?>
<?php } // if news ?>
该代码适用于 2 页,但对于帖子,它没有摘录它使用全文并且它溢出了 p 标签。
该网站的链接在这里: http: //green.romeoothersugar.co.uk
任何帮助,将不胜感激!