Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
<?php
/*
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>')); ?>
        </div>
    </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?

share|improve this question
add comment

3 Answers 3

up vote 0 down vote accepted

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>')); ?>
</div>
share|improve this answer
    
The question is to display an excerpt for a paginated custom post types post pagination to each link. –  kaiser Oct 10 '12 at 14:35
    
I don't get that from reading it at all. Hopefully your answer is right. –  mrwweb Oct 10 '12 at 19:54
    
Hm. Maybe you're right and he showed the code because he got exactly no clue :) –  kaiser Oct 10 '12 at 20:39
    
I did not mention pagination. This sorted out. thanks! –  user1735118 Oct 11 '12 at 6:19
add comment

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>
</h1>

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

share|improve this answer
    
The question is to display an excerpt for a paginated custom post types post pagination to each link. –  kaiser Oct 10 '12 at 14:34
add comment

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.

<?php 
/** 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()
    )
        return;

    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="#'
        ,$n
        ,$n
        ,trim( $curr )
    );
    /*$output = apply_filters(
         'the_excerpt'
        ,$output
    );*/

    // 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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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