Template Name: second

<?php get_header(); ?>

<?php query_posts(array('post_type'=>'event')); ?>
    <?php if(have_posts()) while(have_posts()) : the_post(); ?>
    <div id="post-<?php the_ID(); ?>" class="entry">
        <div class="thumbnail"><?php the_post_thumbnail('full'); ?></div>
        <h1 class="title"><?php the_title(); ?></h1>
        <div class="content page">
            <?php the_content(); ?>
            <?php wp_link_pages(array('before' => '<div class="page-link">'.__('Pages', 'cpotheme').':', 'after' => '</div>')); ?>
    <?php endwhile; ?>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

The page acts like an index.php What should I amend in order to make the title as the link to the full page and make display only an excerpt of the content?

3 Answers 3


You only need two small changes (1st and 3rd lines), though I also took the liberty of tweaking the classes on the div to what seemed more appropriate:

<h1 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<div class="excerpt event">
   <?php the_excerpt(); ?>
   <?php wp_link_pages(array('before' => '<div class="page-link">'.__('Pages', 'cpotheme').':', 'after' => '</div>')); ?>
  • The question is to display an excerpt for a paginated custom post types post pagination to each link.
    – kaiser
    Oct 10, 2012 at 14:35
  • I don't get that from reading it at all. Hopefully your answer is right.
    – mrwweb
    Oct 10, 2012 at 19:54
  • Hm. Maybe you're right and he showed the code because he got exactly no clue :)
    – kaiser
    Oct 10, 2012 at 20:39
  • I did not mention pagination. This sorted out. thanks! Oct 11, 2012 at 6:19

You'll need to form a html anchor tag using Wordpress functions, here's the example.

Example -

<h1 class="title">
    <a href="<?php the_permalink(); ?>" title="<?php printf( 'Permalink to %s', the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>

And to display only excerpt there's functions called the_excerpt()

  • The question is to display an excerpt for a paginated custom post types post pagination to each link.
    – kaiser
    Oct 10, 2012 at 14:34

First off: Interesting Question!

Second: you need to add the <!--nextpage--> tag in your post one or multiple times. Else it won't work.

The plugin:

What this plugin does is intercepting the output of get_permalink(), which is called internally by wp_link_pages(). Inside get_permalink(), we got the get_post_permalink() function that returns for custom post types. There we find the 'post_type_link'-filter and this is where we hook in.

Then we take the global $pages, which holds an array of the post content splitted by the <!--nextpage--> HTML comment. Our static variable is a counter that helps us determining which part we should return - based on the times the function was called (starting at 0).

The last thing is that we append this part from $pages to our post link. As the esc_url() function intercepts our permalink and would mess up all our Uppercase letters, spaces, etc., we attach a single firing filter there too and just return the original string.

/** Plugin Name: (#67750) »kaiser« Append excerpt to post pagination */

 * Callback for get_post_permalink() that is called by get_permalink() for
 * custom post types. We append the $GLOBALS['pages'][ $current ] excerpt here.
 * @param  string $post_link The original posts page link
 * @param  object $post The post object
 * @param  mixed boolean/string $leavename
 * @param  mixed boolean/string $sample A sample link
 * @return string $post_link
function wpse67750_pagination_excerpt( $post_link, $post, $leavename, $sample )
    if (
        'YOUR_POST_TYPE' !== get_post_type()
        OR ! in_the_loop()
        OR ! is_singular()

    static $n = 0;
    // The global pages array: Contains the current post type pages
    global $pages;

    // We need a callback to reserve the original appended string
    // not messed up by the esc_url() function.
    add_filter( 'clean_url', 'wpse67750_pagination_url_cb', 10, 3 );

    // The current page content
    $curr = $pages[ $n++ ];

    // Build the output
    // Wrap it up for easy targeting via CSS and JS
    // Also append a non visible single HTML tag to allow closing the still open anchor
    $output = sprintf(
         '"> %s <span class="excerpt" id="page-%s">%s</span><a style="display:none" rel="nofollow" href="#'
        ,trim( $curr )
    /*$output = apply_filters(

    // Append to the link
    return $post_link.$output;
add_filter( 'post_type_link', 'wpse67750_pagination_excerpt', 10, 4 );

 * The callback to preserve the string appended to the permalink
 * @param  string $url Escaped
 * @param  string $orig_url Not escaped
 * @param  string $context 'display'
function wpse67750_pagination_url_cb( $url, $orig_url, $context )
    // Only run once
    remove_filter( current_filter(), __FUNCTION__ );

    // Return the non escaped original
    return $orig_url;

The solution is not completely perfect. I hadn't got around getting rid of the first number and there seems to be a slight problem with retrieving the last link in some cases. It also had the problem, that core doesn't offer a possibility to get rid of the appended </a> closing tag, so I had to add fake links there. Those don't get displayed, won't be followed by search engines and don't harm. They're just not beautiful, but that's the only possibility.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.