[Resolved] Last updated in footer entry-meta

Home Forums Support [Resolved] Last updated in footer entry-meta

Home Forums Support Last updated in footer entry-meta

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #618187
    Daren

    Is there a way to show the last updated date in the footer meta and still display the post date below the title?

    #618329
    Tom
    Lead Developer
    Lead Developer

    We should be able to code that up πŸ™‚

    Do you want it to display in the post excerpt, the single post or both?

    #618377
    Daren

    Lets go with both.

    #618656
    Tom
    Lead Developer
    Lead Developer

    So the best way to do this right now is to append it to the tags:

    add_filter( 'generate_tag_list_output', 'tu_add_updated_date_to_footer_meta' );
    function tu_add_updated_date_to_footer_meta( $output ) {
        $time_string = false;
    
        if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
            $time_string = '<time class="updated" datetime="%1$s" itemprop="dateModified">%2$s</time>';
        }
    
        if ( $time_string ) {
            $time_string = sprintf( $time_string,
                esc_attr( get_the_modified_date( 'c' ) ),
                esc_html( get_the_modified_date() )
            );
    
            $time_string = '<span class="updated-footer-date">' . $time_string . '</span>';
        }
    
        return $output . $time_string;
    }

    Let me know if this does it or not πŸ™‚

    #618707
    Daren

    It displays the date below the tag meta as July 7, 2018. How do I add the Last Updated text?
    I you need to look I updated the first post with the URL.

    #618751
    Daren

    Did more testing and the date only shows if a post has a tag defined.

    #618881
    Daren

    Ok, I think I got it with the help of some old code. Could you please review the code, it does work.

    
    <?php
    if ( ! function_exists( 'generate_entry_meta' ) ) :
    /**
     * Prints HTML with meta information for the categories, tags.
     *
     * @since 1.2.5
     */
        function generate_entry_meta() 
        {
            $categories = apply_filters( 'generate_show_categories', true );
            $tags = apply_filters( 'generate_show_tags', true );
            $comments = apply_filters( 'generate_show_comments', true );
            $date = apply_filters( 'generate_post_date', true );
            $author = apply_filters( 'generate_post_author', true );
            
            if ( 'post' == get_post_type() ) {
    
                if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
                    $time_string = '<time class="updated-on" datetime="%1$s" itemprop="dateModified">%2$s</time>';
    
                    $time_string = sprintf( $time_string,
                        esc_attr( get_the_modified_date( 'c' ) ),
                        esc_html( get_the_modified_date() )
                    );
                    
                    // If our date is enabled, show it
                    if ( $date ) :
                        printf( '<span class="entry-date updated">%1$s</span>',
                            sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
                                esc_url( get_permalink() ),
                                esc_attr( get_the_time() ),
                                $time_string
                            )
                        );
                    endif;
    
                    // If our author is enabled, show it
                    if ( $author ) :
    
                        $origional_author = get_the_author();
                        $modified_author = get_the_modified_author();
    
                        // If modified by a new author show it
                        if ( $origional_author !== $modified_author ) {
    
                            printf( ' <span class="modified-byline">%1$s</span>',
                                sprintf( '<span class="modified-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_modified_author() ) ),
                                    esc_html( get_the_modified_author() )
                                )
                            );                    
                        }                  
                    endif;
                }
    
                $categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'generate' ) );
                if ( $categories_list && $categories ) {
                    printf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
                        _x( 'Categories', 'Used before category names.', 'generate' ),
                        $categories_list
                    );
                }
    
                $tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'generate' ) );
                if ( $tags_list && $tags ) {
                    printf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>',
                        _x( 'Tags', 'Used before tag names.', 'generate' ),
                        $tags_list
                    );
                }
            }
    
            if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) && $comments ) {
                echo '<span class="comments-link">';
                comments_popup_link( __( 'Leave a comment', 'generate' ), __( '1 Comment', 'generate' ), __( '% Comments', 'generate' ) );
                echo '</span>';
            }
        }
    endif;
    
    #618958
    Leo
    Staff
    Customer Support

    Hey! Tom’s wife is in labor, he will get to this topic as soon as he can πŸ™‚

    #619397
    Tom
    Lead Developer
    Lead Developer

    That works, but using a filter is preferred. However, it is required that tags or categories are active in order to add the filter (for now).

    The solution you found will work until we add a hook into the meta area πŸ™‚

    #619423
    Daren

    Thank you.

    #619425
    Tom
    Lead Developer
    Lead Developer

    No problem πŸ™‚

    #619443
    Daren

    Hey back on the filter idea, could we use the generate_category_list_output and display before the cats are displayed?

    #619760
    Daren

    Took your advice and went the filter route.

    
    add_filter( 'generate_category_list_output', 'dw_add_updated_date_to_footer_meta' );
    function dw_add_updated_date_to_footer_meta( $output ) {
        $time_string = false;
    
        if ( ! is_front_page() && ! is_home() ) {
    
            if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
                $time_string = '<time class="updated" datetime="%1$s" itemprop="dateModified">%2$s %3$s</time>';
            }
    
            if ( $time_string ) {
                $time_string = sprintf( $time_string,
                    esc_attr( get_the_modified_date( 'c' ) ),
                    __( 'Last Updated:','generatepress'),
                    esc_html( get_the_modified_date() )
                );
    
                $time_string = '<span class="updated-on">' . $time_string . '</span>';
            }
        }
        return $time_string . $output;
    }
    

    Works fine.

    #619826
    Tom
    Lead Developer
    Lead Developer

    Awesome! Glad you got it working πŸ™‚

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