Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi there!

    The Custom HTML markup feature from the widget is flexible, but not that much ??

    For this, the recommended way would be via WPP filters. Hooking into wpp_custom_html -for example- would give you full control of the HTML output. The example code should help you figure out most of it.

    Alternatively, although not recommended, you could also modify WPP’s code directly to add your custom date function. The function that renders the date is located here (as of ver. 3.2.2).

    When I say “not recommended” is because hacking plugins code can turn into a tedious task: every time you upgrade the plugin, all changes made to its files will be overwritten with the new ones during the process. So, you either never ever update the plugin (which is a bad idea since you’ll lose access to new features and/or bug fixes) or you keep patching the code after every update.

    Thread Starter socca1157

    (@socca1157)

    Thanks for the link to the example, it was perfect!

    Here’s what I came up with if anyone else wants to use it.

    /**
     * Prettify the date for populer posts
     */
    function my_custom_single_popular_post( $post_html, $p, $instance ){
        $category = get_the_category( $p->id );
        $cat_name=$category[0]->cat_name;
        $days = round((date('U') - strtotime($p->date)) / (60*60*24));
        if ($days==0) {$wpp_time="Posted Today";}
        elseif ($days==1) {$wpp_time="Posted Yesterday";}
        else {$wpp_time="Posted ".$days." days ago";}
        $output = '<li>
    <div class="publish_time">'.$wpp_time.'</div>
    <a href="' . get_the_permalink($p->id) . '" target="_blank" class="wpp-post-title" title="' . esc_attr($p->title) . '">
    <img class="wpp-thumbnail" src="'.wp_get_attachment_url(get_post_thumbnail_id($p->id)).'" title="' . esc_attr($p->title) . '" alt="' . esc_attr($p->title) . '"></a>
    <a href="' . get_home_url(). '/'.strtolower($cat_name).'/" target="_blank" class="wpp-post-category">' . $cat_name . '</a>
    <a href="' . get_the_permalink($p->id) . '" target="_blank" class="wpp-post-title" title="' . esc_attr($p->title) . '">' . $p->title . '</a>
     </li>';
        return $output;
    }
    add_filter( 'wpp_post', 'my_custom_single_popular_post', 10, 3 );
    Plugin Author Hector Cabrera

    (@hcabrera)

    Glad to know you got it working. And also thanks for sharing the code, I’m sure other users will find it helpful ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do I "Prettify" the {date} output?’ is closed to new replies.