Skip to:
Content
Pages
Categories
Search
Top
Bottom

change styling if freshness less than 24 hours


  • neon67
    Participant

    @neon67

    Robin, is it possible for me to place new css class in the date freshness.
    My dream is to mark all posts in the last 24 hours in green.

    Is it possible to somehow connect the css selector to dates (there will be only “hours” and “minutes”, but there will be no “day”)?Unfortunately, I disabled the pack style because there were conflicts. And the settings are now the initial bbp – you can see them on the website (the top 10 at main page face were written in the last 24 hours)
    website

Viewing 16 replies - 1 through 16 (of 16 total)

  • Robin W
    Moderator

    @robin-w

    you don’t need stylepack, it’s just that the answer is different if you do !

    I’ll come back with code when I get a moment 🙂


    neon67
    Participant

    @neon67

    OK thanks


    Robin W
    Moderator

    @robin-w

    try this

    add_filter ('bbp_get_forum_freshness_link' , 'rew_check_freshness', 10 , 6 ) ;
    
    function rew_check_freshness ($anchor, $forum_id, $time_since, $link_url, $title, $active_id) {
    	$last_active = get_post_meta( $forum_id, '_bbp_last_active_time', true );
    	$diff = strtotime('now') - strtotime($last_active) ;
    	if ($diff<86400) {
    	$anchor = '<span class="fresh">'.$anchor.'</span>' ;
    	}
    return $anchor ;	
    }

    This adds an extra span class called ‘fresh’ if the last active is less than 24 hours.

    you can then style this in css eg

    .fresh {
    background-color : green ;
    }

    neon67
    Participant

    @neon67

    OK, put it in. But I did not find the new class anywhere on the page (.22fresh). The cache was cleared.
    Maybe the theme will not start up?


    Robin W
    Moderator

    @robin-w

    ahh – think I have misunderstood now I re-read, given the post you attached to, I thought your question was regarding the freshness columm, but now I don’t know.

    my code adds a class in the freshness column

    <li class="bbp-forum-freshness">
    <span class="fresh"><a href="http://gos.rewweb.co.uk/forums/topic/eferwer/" title="EFERWER">8 hours, 14 minutes ago</a></span>

    so can you explain exactly what you want to turn green?


    neon67
    Participant

    @neon67

    The same place where you added the picture today.)))
    bbpress.org/forums/topic/create-a-link-image-for-last-post-in-forum/

    Namely # bbpress-forums .bbp-topic-freshness a


    neon67
    Participant

    @neon67


    Robin W
    Moderator

    @robin-w

    ok, that’s where it should be, and it should work.

    where are you putting the code ?


    Robin W
    Moderator

    @robin-w

    Just realised, frenchlemans wanted it against the forum list – but you show nothing there, so you want it against the topic list in each forum – yes ?


    neon67
    Participant

    @neon67

    function.php childe theme
    then search f7 new .class in view-source:https: …. none


    neon67
    Participant

    @neon67

    #bbp-topic-8191 > li.bbp-topic-freshness in code

    #bbpress-forums .bbp-topic-freshness a { in css

    this is a small box with a time stamp (see pic. above) white background now


    Robin W
    Moderator

    @robin-w

    ok try this for topics in a forum

    add_filter ('bbp_get_topic_freshness_link' , 'rew_check_freshness2', 10 , 5 ) ;
    
    function rew_check_freshness2 ($anchor, $topic_id, $time_since, $link_url, $title) {
    	$last_active = get_post_meta( $topic_id, '_bbp_last_active_time', true );
    	$diff = strtotime('now') - strtotime($last_active) ;
    	if ($diff<86400) {
    	$anchor = '<span class="fresh">'.$anchor.'</span>' ;
    	}
    return $anchor ;	
    }

    neon67
    Participant

    @neon67

    The class appeared in the code!
    Moment, now I will figure out why the css does not catch it… and finally give the picture the result !…


    neon67
    Participant

    @neon67

    So, the final css looks like this (you must put “a”)

    #bbpress-forums .bbp-topic-freshness .dayfresh  a {
    background-color : #f4ffe8 ;
    	border: 1px dashed;
    	color: #475656;
    }

    also 86400 looks a lot – captures the 2nd day. Perhaps need to set 23 hours. But these are little things ))

    Thanks to Robin for the great code!))
    I think this is a useful find for those who visit the forum once a day and immediately see how many topics have been updated in the last day.
    Colored blocks are very noticeable – it’s better than straining and peering at the date numbers.


    neon67
    Participant

    @neon67

    Supplement about setting the time.
    If you do not live in London, you need to add or subtract the number of hours in accordance with your time zone. Then get exactly 24 hours indentation.


    Robin W
    Moderator

    @robin-w

    yes, strtotime(‘now’) will pick up gmt, so needs adjusting, you night want to look at

    $now = date_create( date_i18n( 'Y-m-d H:i:s' ) );

Viewing 16 replies - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.
Skip to toolbar