Black Friday Sale! Get up to $30 off GP Premium! Learn more ➝

[Resolved] 'entry-meta' content customization

Home Forums Support [Resolved] 'entry-meta' content customization

Home Forums Support 'entry-meta' content customization

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #186719
    Dominik

    Hi Folks,

    I’ve just begun my adventure with GeneratePress, starting with the Premium version. I have not-so-small problem and unfortunately not-so-big knowledge about coding and WordPress.

    I’d like to add some infromation to replace the ‘entry-meta’ div content. New content should vary, depending on which category is assigned to the post. I also want to use Custom Tags with this, for example showing the post’s difficulty (f.e. as a number from 1 to 10).

    It should be easy. But fro me it is not. Where to begin? How should I do this? As a child theme? Plugin? Or both? Please show me the way and give some tips. I’d be really grateful. 🙂

    #186803
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    So you want to replace the byline etc.. with custom text for each post? Any examples?

    #186812
    Dominik

    Thanks for your response! 🙂

    I’d like to have two (in the future – even more!) different post’s categories and I want them to be displayed much differently, for example:

    1st category: ARTICLES

    <<post title>>
    Published: <<date and hour>> as part of <<category name with icon, just like below the content>>. Commented <<number>> times.
    <<content>>
    <<tags, no information about category or comments>>

    2nd category: QUESTIONS //from readers
    <<title>>
    Asked <<date and hour>> by <<name of reader – from custom tag>>. Case difficulty: <<number from 1 to 10, from custom tag>>.
    <<content>>
    <<tags, no information about category or comments>>

    That template may seem to be weird for you, but my language (Polish), I can say, supports it. 🙂 I wish I’ve explained everything properly.

    #187085
    Tom
    Lead Developer
    Lead Developer

    Doing something like this is pretty involved/requires a decent amount of custom programming.

    You would have to add custom fields for things like the name of the reader.

    Then you would need a decent amount of conditionals going on in the post meta function to tell which category you’re using etc..

    If you know a bit of programming, asking over on http://wordpress.stackexchange.com might be the quickest way to get an answer.

    Or using a plugin like Advanced Custom Fields to create the custom fields for the name etc..

    #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 5 years, 7 months ago by Tom.
    • This reply was modified 5 years, 7 months ago by Tom.
    #187474
    Tom
    Lead Developer
    Lead Developer

    Awesome, great job! Thanks for sharing the code 🙂

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.