Reply To: 'entry-meta' content customization

Home Forums Support 'entry-meta' content customization Reply To: 'entry-meta' content customization

Home Forums Support 'entry-meta' content customization Reply To: 'entry-meta' content customization

#187383
Dominik

Hi Tom,

thank you for your tips! Being given them instead of ready-to-use solutions (like codes or sth) is exactly the way I like. I’ve achieved my dreamed result with very simple coding, just by myself. I’ll post an image and my code here, hope it’ll help someone. 🙂 If anything is incorrect, please let me know. You’ll also see how to move Categories and Comments sections from bottom to the top of an article.

The hardest was to find a function responsible for the so-called byline. It’s the generate_posted_on() function. Here’s my result (layout still in progress):

http://www.samachemia.net/wp-content/uploads/2016/04/screenshot.png

I’ve created child theme and added this code (copy-paste-change method :)) in child theme’s functions.php file:

if ( ! function_exists( 'generate_posted_on' ) ) :
/**
 * Prints HTML with meta information for the current post-date/time and author.
 */
function generate_posted_on() {

	if ( 'post' !== get_post_type() ) 
		return;
	
	$categories = get_the_category();
 
	if ( (! empty( $categories )) AND ($categories[0]->name == 'Krótkie pytania')) {

	$date = apply_filters( 'generate_post_date', true );
	$author = apply_filters( 'generate_post_author', true );
		
	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Odpowiedź z %2$s, %5$s</time>';
	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
		$time_string .= '<time class="updated" datetime="%3$s" itemprop="dateModified">%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() ),
		esc_attr( get_the_time() )
	);
	
	// If our date is enabled, show it
	if ( $date ) :
		printf( '<span class="posted-on">%1$s</span>',
			$time_string
		);
	endif;

	$zadajacy = get_post_meta( get_the_ID(), 'zadajacy', true );

	echo '. Pytanie nadesłał(a) <span class="zadajacy">' . $zadajacy . '</span>.';
	
	if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
		echo '<span class="comments-link">';
		comments_popup_link( __( 'Leave a comment', 'generatepress-child' ), __( '1 Comment', 'generatepress-child' ), __( '% Comments', 'generatepress-child' ) );
		echo '</span>';
	}
	}
else { //jeśli nie krótkie pytanie, to co?

	$date = apply_filters( 'generate_post_date', true );
	$author = apply_filters( 'generate_post_author', true );
		
	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Opublikowano %2$s, %5$s</time>';
	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
		$time_string .= '<time class="updated" datetime="%3$s" itemprop="dateModified">%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() ),
		esc_attr( get_the_time() )
	);
	
	// If our date is enabled, show it
	if ( $date ) :
		printf( '<span class="posted-on">%1$s</span>',
			$time_string
		);
	endif;
	
	/* // If our author is enabled, show it
	if ( $author ) :
		printf( ' <span class="byline">%1$s</span>',
			sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <a class="url fn n" href="%2$s" title="%3$s" rel="author" itemprop="url"><span class="author-name" itemprop="name">%4$s</span></a></span>',
				__( 'by','generate'),
				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
				esc_attr( sprintf( __( 'View all posts by %s', 'generate' ), get_the_author() ) ),
				esc_html( get_the_author() )
			)
		);
	endif; */

$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generate' ) );
	if ( $categories_list ) {
		printf( ' w kategorii <span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>.',
			_x( 'Categories', 'Used before category names.', 'generate' ),
			$categories_list
		);
	}

	if ( ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
		echo '<span class="comments-link">';
		comments_popup_link( __( 'Leave a comment', 'generatepress-child' ), __( '1 Comment', 'generatepress-child' ), __( '% Comments', 'generatepress-child' ) );
		echo '</span>';
	}
}
}
endif;

And a little bit of CSS in child theme’s style.css file:

.cat-links {
	display: inline;
}

.comments-link {
	display: inline;
	float: right;
}

.zadajacy:before {
	content: "\f007";
	font-family: FontAwesome;
  	font-weight: normal;
 	font-style: normal;
	display: inline-block;
	text-decoration: inherit;
	position:relative;
	margin-right: 5px;
	width: 13px;
	text-align:center;
}

Hope somebody’ll find it useful. 🙂

Best regards!

  • This reply was modified 8 years ago by Tom.
  • This reply was modified 8 years ago by Tom.