【发布时间】:2014-09-18 21:07:47
【问题描述】:
我有一个自定义页面模板设置为将类别帖子拉到“页面”上 我已经设置了一个功能来显示摘录。 “阅读更多>>”是存在的,但是,帖子 ID 并未拉入各个帖子的永久链接。每篇文章后的摘录都链接到我创建的同一页面。
functions.php-->
function excerpt($num) {
$limit = $num+1;
$excerpt = explode(' ', get_the_excerpt(), $limit);
array_pop($excerpt);
$excerpt = implode(" ",$excerpt). ' <a href="' . get_permalink($post->ID) . '" class="more-link" title="Read More">Read More >></a>';
echo $excerpt;
}
function excerpt_length($length) {
return 40;
}
add_filter('excerpt_length', 'excerpt_length');
content.php-->
<div class="entry-content">
<?php if ( is_category() || is_archive() || is_search() || is_home() ) {
the_excerpt();
} else {
the_excerpt();
} ?>
</div>
-------我一直在测试的另一个功能类似的结果,其中包括全局 $post。
function themprefix_excerpt_read_more_link($output) {
global $post;
return $output . ' <a href="' . get_permalink($post->ID) . '" class="more-link" title="Read More">Read More >></a>';
}
add_filter( 'the_excerpt', 'themprefix_excerpt_read_more_link' );
自定义页面模板 -->
<?php get_header(); ?>
<div id="main" class="row-fluid">
<div id="main-left" class="span8">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page' ); ?>
<?php
$catPost = get_posts('cat=225&posts_per_page=3');
foreach ($catPost as $post) : setup_postdata($post);
?>
<?php get_template_part('content'); ?>
<?php endforeach;?>
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>
</div><!-- #main-left -->
<?php get_sidebar(); ?>
<div class="clearfix"></div>
</div><!-- #main -->
<?php get_footer(); ?>
【问题讨论】: