Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #81680
    Alexandre
    Participant

    Hi,
    I would like to add code to catchresponsive_entry_meta in the single view only. The code in content.php is for all views (single, index etc.) – how do I add some code for single view only and how could I make this consistent via child theme, since my code has to go to inc/catchresponsive-core.php

    thank you!

    #81684
    Pratik
    Keymaster

    Hi @Alexandre,
    Yes, all the customization has to be made via Child Theme.

    To achieve what you want, you can follow the steps below:
    1. You will need to create a child theme for Catch Responsive Pro. Its details can be found here. (Just download your respective Child Theme from Samples newr the bottom of the post)
    2. Then you can past this code in your child theme’s functions.php

    
    /**
     * Prints HTML with meta information for the current post-date/time and author.
     *
     * @since Catch Responsive 1.0
     */
    function catchresponsive_entry_meta() {
    	if( !is_single() ) {
    		//Bail early if it is not a post page
    		return;
    	}
    	echo '<p class="entry-meta">';
    
    	$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
    
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
    	}
    
    	$time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date() ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date() )
    	);
    
    	printf( '<span class="posted-on">%1$s<a href="%2$s" rel="bookmark">%3$s</a></span>',
    		sprintf( _x( '<span class="screen-reader-text">Posted on</span>', 'Used before publish date.', 'catch-responsive' ) ),
    		esc_url( get_permalink() ),
    		$time_string
    	);
    
    	if ( is_singular() || is_multi_author() ) {
    		printf( '<span class="byline"><span class="author vcard">%1$s<a class="url fn n" href="%2$s">%3$s</a></span></span>',
    			sprintf( _x( '<span class="screen-reader-text">Author</span>', 'Used before post author name.', 'catch-responsive' ) ),
    			esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    			esc_html( get_the_author() )
    		);
    	}
    
    	if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) {
    		echo '<span class="comments-link">';
    		comments_popup_link( esc_html__( 'Leave a comment', 'catch-responsive' ), esc_html__( '1 Comment', 'catch-responsive' ), esc_html__( '% Comments', 'catch-responsive' ) );
    		echo '</span>';
    	}
    
    	edit_post_link( esc_html__( 'Edit', 'catch-responsive' ), '<span class="edit-link">', '</span>' ); 
    
    	echo '</p><!-- .entry-meta -->';
    }
    

    The code on the top of function is the addition that does the work you desire. Let me know if this works out or not.

    #81710
    Alexandre
    Participant

    Thank you, that helps a lot. Now I don’t habe any meta in index view?

    #81722
    Pratik
    Keymaster

    hi @Alexandre,
    I thought you wanted the meta to be only shown on single page and not index pages?

    #81839
    Alexandre
    Participant

    Hi,
    sorry for this misunderstanding. I meant, that I would like to have different meta in single and index view.
    thank you!

    #81870
    Pratik
    Keymaster

    Hi,
    Ok, same steps need to be followed, but with exception to the function. Use following code instead:

    
    /**
     * Prints HTML with meta information for the current post-date/time and author.
     *
     * @since Catch Responsive 1.0
     */
    function catchresponsive_entry_meta() {
    	if( is_single() ) {
    		//Meta info for single page
    		echo '<p class="entry-meta">';
    
    		$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
    
    		if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    			$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
    		}
    
    		$time_string = sprintf( $time_string,
    			esc_attr( get_the_date( 'c' ) ),
    			esc_html( get_the_date() ),
    			esc_attr( get_the_modified_date( 'c' ) ),
    			esc_html( get_the_modified_date() )
    		);
    
    		printf( '<span class="posted-on">%1$s<a href="%2$s" rel="bookmark">%3$s</a></span>',
    			sprintf( _x( '<span class="screen-reader-text">Posted on</span>', 'Used before publish date.', 'catch-responsive' ) ),
    			esc_url( get_permalink() ),
    			$time_string
    		);
    
    		if ( is_singular() || is_multi_author() ) {
    			printf( '<span class="byline"><span class="author vcard">%1$s<a class="url fn n" href="%2$s">%3$s</a></span></span>',
    				sprintf( _x( '<span class="screen-reader-text">Author</span>', 'Used before post author name.', 'catch-responsive' ) ),
    				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    				esc_html( get_the_author() )
    			);
    		}
    
    		if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) {
    			echo '<span class="comments-link">';
    			comments_popup_link( esc_html__( 'Leave a comment', 'catch-responsive' ), esc_html__( '1 Comment', 'catch-responsive' ), esc_html__( '% Comments', 'catch-responsive' ) );
    			echo '</span>';
    		}
    
    		edit_post_link( esc_html__( 'Edit', 'catch-responsive' ), '<span class="edit-link">', '</span>' ); 
    
    		echo '</p><!-- .entry-meta -->';
    	}
    	else {
    		//Meta for pages other than single
    		echo '<p class="entry-meta">';
    
    		$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
    
    		if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    			$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
    		}
    
    		$time_string = sprintf( $time_string,
    			esc_attr( get_the_date( 'c' ) ),
    			esc_html( get_the_date() ),
    			esc_attr( get_the_modified_date( 'c' ) ),
    			esc_html( get_the_modified_date() )
    		);
    
    		printf( '<span class="posted-on">%1$s<a href="%2$s" rel="bookmark">%3$s</a></span>',
    			sprintf( _x( '<span class="screen-reader-text">Posted on</span>', 'Used before publish date.', 'catch-responsive' ) ),
    			esc_url( get_permalink() ),
    			$time_string
    		);
    
    		if ( is_singular() || is_multi_author() ) {
    			printf( '<span class="byline"><span class="author vcard">%1$s<a class="url fn n" href="%2$s">%3$s</a></span></span>',
    				sprintf( _x( '<span class="screen-reader-text">Author</span>', 'Used before post author name.', 'catch-responsive' ) ),
    				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    				esc_html( get_the_author() )
    			);
    		}
    
    		if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) {
    			echo '<span class="comments-link">';
    			comments_popup_link( esc_html__( 'Leave a comment', 'catch-responsive' ), esc_html__( '1 Comment', 'catch-responsive' ), esc_html__( '% Comments', 'catch-responsive' ) );
    			echo '</span>';
    		}
    
    		edit_post_link( esc_html__( 'Edit', 'catch-responsive' ), '<span class="edit-link">', '</span>' ); 
    
    		echo '</p><!-- .entry-meta -->';
    	}
    }
    

    You need just a bit of programming knowledge for this though. There are two blocks, if and else. The if block (With comment //Meta info for single page) will be used for single view and the else block(With comment //Meta for pages other than single) will be used for index views. Just edit those blocks.

    Let me know how it goes.

    Regards,
    Pratik

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘changing catchresponsive_entry_meta in "single" view’ is closed to new replies.