• Resolved janew

    (@janew)


    Theme TwentyTwenty shows the excerpt below the title, but I changed that to show the date instead. I wanted the time to be there, but not obvious, so I created a tooltip that shows the date and time of posting:

    <div id="post-date"><span title="Published on <?php echo the_time('F j, Y'); ?> at <?php echo the_time(); ?>"><?php echo the_date(); ?></span></div>

    It works great!

    But when I want to add that to the entry title, the text shows in the tooltip, but the date and time print above the title.

    		if ( is_singular() ) {
    			the_title( '<h3 class="entry-title">', '</h3>' );
    		} else {
    			the_title( '<h3 class="entry-title"><span title="Published on ' . _e( the_time('F j, Y') ) . ' at ' . _e( the_time() ) . '">', '</span></h3>' );
    		}

    I’m quite the amateur – it took me at least an hour to figure out how to “translate” the php from the first code into something that didn’t cause an error in the second code, but I cannot figure out how to make it write in the tooltip rather than above the title.

    My point is, I’m really trying to figure this stuff out, but I also have no idea what I am doing, so when I get to this point, I’m lost.

    Please help?

    Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • I don’t understand.
    You mean like this :
    https://ibb.co/grk6H08

    ?

    Thread Starter janew

    (@janew)

    @corrinarusso Yes that’s a form of tool tip, though styled a bit, I guess. I’m not looking for styling advice though, just want to make it work using the html title attribute.
    https://ibb.co/PF7Mdnn

    But I wasn’t giving you styling advice.
    You should be usig libraries that are available to you is all – make maintenance much easier :
    https://getbootstrap.com/docs/4.0/components/tooltips/

    To fix your loop, just put it in a variable :

    if ( is_singular() ) {
    $dateis=date('F j, Y');
    $timeis=date('g:i a');
                echo the_title( '<h3 class="entry-title"><span title="Published on ' . $timeis . ' at ' . $timeis . '">', '</span></h3>' );
    Thread Starter janew

    (@janew)

    Sorry didn’t mean to imply that you were giving styling advice … everything I googled wanted to tell me how to style it and I didn’t want you to waste your time explaining all that in case that’s what you thought I was looking for, since you said you didn’t understand.

    Anyway, the code you provided is a good starting point, and I was able to “fix” it to my needs.

    First off, I figured out the $ lines need to go before the if statement. And in the span the first php should read $dateis. I thought putting echo before the_title might screw it up, but it did not – but neither did removing it altogether. So I guess it’s unnecessary, sometimes….
    Once I got that fixed there was one other major problem: it was only showing the current date and time, and changed on every reload. Some digging – and trial and error – had me realizing that the $ lines needed to read as

    $dateis=get_the_date();
    $timeis=get_the_time();

    Once I did that, the post date was then showing in the tool tip, as I want.

    So thank you for putting me on the right track!

    Ah yes, re: the post time, not the current time.

    Sounds good – glad it’s sorted.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘adding date/time to tooltip’ is closed to new replies.