最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Problem in replacing the_content with the_excerpt()

programmeradmin3浏览0评论

I want to add read more to a blog. For that I need to replace the function the_content(). I found it in the loop file and replaced it with the_excerpt() but still posts are being shown of full length. Please help out.

EDIT: Here is the site. The read more is added now(I replaced all the occurences of the_content with the_excerpt). It gave rise to a new problem. All the links on the page are not working correctly. Please have a look.

I want to add read more to a blog. For that I need to replace the function the_content(). I found it in the loop file and replaced it with the_excerpt() but still posts are being shown of full length. Please help out.

EDIT: Here is the site. The read more is added now(I replaced all the occurences of the_content with the_excerpt). It gave rise to a new problem. All the links on the page are not working correctly. Please have a look.

Share Improve this question edited Aug 7, 2011 at 2:33 asked Aug 7, 2011 at 1:40 user2238user2238
Add a comment  | 

1 Answer 1

Reset to default 1

Are you sure you have replaced it in the correct template file?

I found a useful way to tell by adding this to the functions.php file:

<?php
    add_action( 'wp_head', 'adminbar_print_template' );
function adminbar_print_template() {
    global $template, $current_user, $wp_admin_bar;

    get_currentuserinfo();
        /* If you have more than one user deny. Be sure to use your user ID! */
    if ( !is_user_logged_in() && $current_user->ID != '1' )
        return;
    if ( is_admin_bar_showing() )
        $wp_admin_bar->add_menu( array(
            'parent' => false,
            'id' => 'template',
            'title' => $template,
            'href' => '#'
        ));
    else
        print_r( $template );
}
?>

If you have the Show Admin Bar settings set to "show when viewing site", it will output the current template file being used on the page you are viewing. Another possibility could be that your theme uses a loop.php file, and you will need to modify it for the excerpt.

TIP: Add this to your functions.php file so the "Read More" tags are actually links to the posts:

   function new_excerpt_more($more) {
   global $post;
   return '… <a href="'. get_permalink($post->ID) . '">' . 'Read More &raquo;' . '</a>';
   }
   add_filter('excerpt_more', 'new_excerpt_more');
发布评论

评论列表(0)

  1. 暂无评论