Support » Theme: AccessPress Parallax » How to display Year in Post Date

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Hi @dougjoseph I’ve removed your duplicate topic, please don’t do that as it makes it harder for volunteers to support you.

    Edit: This really is a theme specific question and this is the right place to ask for that support.

    dougjoseph

    (@dougjoseph)

    I posted elsewhere because it seems this theme support area is not getting much in the way of eyes or replies.

    I had quickly realized that I could “apply” a general concept of where to tweak date settings (i.e. help that is not theme specific) to my situation, while it would seem that getting help that is specific to this theme is not happening much. Thus, my effort to post a general WordPress question elsewhere.

    dougjoseph

    (@dougjoseph)

    For those insisting I not ask general questions and only ask specific ones, help here in the “specific” thread (instead of just criticizing how I am asking) would be deeply appreciated.

    [ Please do not bump. ]

    • This reply was modified 2 years ago by dougjoseph.
    Michael

    (@alchymyth)

    The general concept of where and how to tweak date settings is /not/ theme specific. It’s WordPress specific.

    this could be, but often is not.
    themes can overwrite the settings for the date as done in the dashboard under ‘settings – general – date format’

    your theme uses archive.php to display the category archive page;
    using this line get_template_part( 'content', get_post_format() ); archive.php calls a file content.php to display the content of each post in that archive page;
    content.php uses this code <?php accesspress_parallax_posted_on(); ?> to show the post date;
    that function accesspress_parallax_posted_on() can be found in /inc/template-tags.php in your theme…

    as you can see, this is not at all specific to WordPress.

    dougjoseph

    (@dougjoseph)

    Michael

    I am both amazed that you can track all that, and grateful for you having done so. I’m happy to be humbled in correction by someone willing to help at the same time as correcting. Thank you.

    dougjoseph

    (@dougjoseph)

    If I am correctly viewing the theme (“specific”) code in template-tags.php, it’s a modified version of what apparently would “normally” (WordPress, “generally”) be found in functions.php. If I had obtained a “general” answer pointing me to that file, I could have “applied” the general answer to my specific situation, by searching for code like it or similar to it, in the theme. It is in that sense that this situation is both general and specific, and it is in that sense I sought to get a general answer, because the history of this area indicated to me that a specific answer was not likely to be forthcoming. I still doubt that I would have received any answer here if I had not posted elsewhere first, but we’ll never know. Nevertheless the help is deeply appreciated.

    dougjoseph

    (@dougjoseph)

    To anyone else looking to achieve the same result (get the year to show in the AccessPress Parallax theme’s display of posts), here’s how:

    Note: This assumes you have a child theme to protect your tweaks from being overwritten if the theme is ever updated. Further down I will mention how to edit the theme directly (not recommended).

    1. In the theme’s folder, go into the /inc/template-tags.php file. Once there, copy the following code (lines 10-46):

    if ( ! function_exists( 'accesspress_parallax_posted_on' ) ) :
    /**
     * Prints HTML with meta information for the current post-date/time and author.
     */
    function accesspress_parallax_posted_on() {
    	$time_string = '<time class="entry-date published" datetime="%1$s"><span class="posted-day">%2$s</span><span class="posted-month">%3$s</span></time>';
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string .= '<time class="updated" datetime="%4$s">%5$s</time>';
    	}
    
    	$time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date( 'd' ) ),
    		esc_html( get_the_date( 'M' ) ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date() )
    	);
    
    	$posted_on = $time_string ;
    
    	$byline = sprintf(
    		_x( 'By %s', 'post author', 'accesspress-parallax' ),
    		'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
    	);
    
    	$post_date = of_get_option('post_date');
    	$post_author = of_get_option('post_author');
    	if($post_date ==  1 || empty($post_date)) :
    	echo '<span class="posted-on">' . $posted_on . '</span>';
    	endif;
    
    	if($post_author ==  1 || empty($post_author)) :
    	echo '<span class="byline"> ' . $byline . '</span>';
    	endif;
    
    }
    endif;

    2. Then go into your child theme’s folder, and edit your “functions.php” file. Paste in the above code (below any other other functions), and tweak it by adding the following portions:

    <span class="posted-year">%4$s</span>

    and

    esc_html( get_the_date( 'Y' ) ),

    …so that the final code looks like this:

    if ( ! function_exists( 'accesspress_parallax_posted_on' ) ) :
    /**
     * Prints HTML with meta information for the current post-date/time and author.
     */
    function accesspress_parallax_posted_on() {
    	$time_string = '<time class="entry-date published" datetime="%1$s"><span class="posted-day">%2$s</span><span class="posted-month">%3$s</span><span class="posted-year">%4$s</span></time>';
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string .= '<time class="updated" datetime="%4$s">%5$s</time>';
    	}
    
    	$time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date( 'd' ) ),
    		esc_html( get_the_date( 'M' ) ),
    		esc_html( get_the_date( 'Y' ) ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date() )
    	);
    
    	$posted_on = $time_string ;
    
    	$byline = sprintf(
    		_x( 'By %s', 'post author', 'accesspress-parallax' ),
    		'<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
    	);
    
    	$post_date = of_get_option('post_date');
    	$post_author = of_get_option('post_author');
    	if($post_date ==  1 || empty($post_date)) :
    	echo '<span class="posted-on">' . $posted_on . '</span>';
    	endif;
    
    	if($post_author ==  1 || empty($post_author)) :
    	echo '<span class="byline"> ' . $byline . '</span>';
    	endif;
    
    }
    endif;

    Finally, if you feel you must edit the theme directly (without a child theme), simply edit the code in the /inc/template-tags.php file, making match the latter example above.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to display Year in Post Date’ is closed to new replies.