WordPress.org

Forums

[resolved] Different Length Excerpts for posts with different classes (4 posts)

  1. jamo_dodger
    Member
    Posted 1 year ago #

    Hello,

    I recently had some help form Alchymyth to add classes to my posts on my blog page and he suggested using:

    <article id="post-<?php the_ID(); ?>" <?php $extra = ( ( $wp_query->current_post % 5 == 0 && !is_paged() ) ? 'full' : 'half' ) . ( ( ( $wp_query->current_post % 5 == 1 || $wp_query->current_post % 5 == 3 ) && !is_paged() ) ? ' left' : '' ); post_class($extra); ?>>

    This works great and in short adds the classes 'full' 'half' and 'half left'.

    I also use the following to change the length of the excerpts of these posts:

    function twentytwelvechild_custom_excerpt_length( $length ) {
    	return 30;
    }
    add_filter( 'excerpt_length', 'twentytwelvechild_custom_excerpt_length', 30 );
    
    function twentytwelvechild_new_excerpt_more($more) {
           global $post;
    	return '... <a href="'. get_permalink($post->ID) . '"><div class="read-more-div">[READ MORE →]</div></a>';
    }
    add_filter('excerpt_more', 'twentytwelvechild_new_excerpt_more');

    This sets all posts to have an excerpt length of 30. My question is how can I have a different excerpt length for the posts with the 'full' class?

    Thank you

    James

  2. alchymyth
    Forum Moderator
    Posted 1 year ago #

    try:

    function twentytwelvechild_custom_excerpt_length( $length ) {
    	global $wp_query;
    	if( $wp_query->current_post%5 == 0 ) return 50;
    	else return 30;
    }
    add_filter( 'excerpt_length', 'twentytwelvechild_custom_excerpt_length', 30 );
  3. jamo_dodger
    Member
    Posted 1 year ago #

    Again works like a charm alchymyth.

    Have bought you a beer (or 2) via your website.

    James

  4. jamo_dodger
    Member
    Posted 1 year ago #

    Have encountered a problem changing the excerpt length of the smaller posts back to 30 words long when using a media query at a max with of 767px.

    Started new thread here:
    http://wordpress.org/support/topic/changing-the-excerpt-length-when-using-a-media-query?replies=1#post-5182946

Topic Closed

This topic has been closed to new replies.

About this Topic