• Resolved Rafa?

    (@ayek)


    Hello!
    Is it possible to add an easy filter which inserts class with value got from the post format?
    I think about something easier than copying the whole function crp_list_link,
    which modified works for me, but I’m concerned about future updates which may change things.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Rafa?

    (@ayek)

    I’ve also changed the title tag.
    Now it looks like that:

    add_filter('crp_list_link','modify_output', 10, 3);
    
    function modify_output( $output, $result, $args ) {
    	
    	$link = get_permalink( $result->ID );
    	
    	$post_format = get_post_format( $result->ID );
    	if (!$post_format) $post_format = 'standard';
    	
    	$output          = '';
    	$title           = crp_title( $args, $result );
    	$link            = crp_permalink( $args, $result );
    	$link_attributes = crp_link_attributes( $args );
    
    	$output .= '<a href="' . $link . '" ' . $link_attributes . ' class="crp_link format-' . $post_format . ' ' . $result->post_type . '-' . $result->ID . '">';
    
    	if ( 'after' === $args['post_thumb_op'] ) {
    		$output .= '<h3 class="crp_title">' . $title . '</h3>'; // Add title when required by settings.
    	}
    
    	if ( 'inline' === $args['post_thumb_op'] || 'after' === $args['post_thumb_op'] || 'thumbs_only' === $args['post_thumb_op'] ) {
    		$output .= '<figure>';
    		$output .= crp_get_the_post_thumbnail(
    			array(
    				'postid'             => $result,
    				'thumb_height'       => $args['thumb_height'],
    				'thumb_width'        => $args['thumb_width'],
    				'thumb_meta'         => $args['thumb_meta'],
    				'thumb_html'         => $args['thumb_html'],
    				'thumb_default'      => $args['thumb_default'],
    				'thumb_default_show' => $args['thumb_default_show'],
    				'scan_images'        => $args['scan_images'],
    				'class'              => 'crp_thumb',
    			)
    		);
    		$output .= '</figure>';
    	}
    
    	if ( 'inline' === $args['post_thumb_op'] || 'text_only' === $args['post_thumb_op'] ) {
    		$output .= '<h3 class="crp_title">' . $title . '</h3>'; // Add title when required by settings.
    	}
    
    	$output .= '</a>';
    	
    	return $output;
    }

    Better approach maybe?

    Plugin Author Ajay

    (@ajay)

    Instead of rewriting the whole function, one option could be to do a str_replace for class="crp_link with class="crp_link format-' . $post_format

    Thread Starter Rafa?

    (@ayek)

    It’s good idea, definitely, however, I’ll stick with the whole function. It allows me to fix another issue.
    I don’t use placeholder image, then when post hasn’t got featured image, function prints empty <figure></figure> tag.

    Condition:
    if ( 'inline' === $args['post_thumb_op'] || 'after' === $args['post_thumb_op'] || 'thumbs_only' === $args['post_thumb_op'] )
    replaced to:
    if ( has_post_thumbnail( $result->ID ) )

    Plugin Author Ajay

    (@ajay)

    That makes sense. Plus let me also take a look at figure tags as it is a valid point you raised.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Class depending on Post Format’ is closed to new replies.