WordPress.org

Ready to get started?Download WordPress

Forums

Mingle Forum
PHP code to get number of new Mingle posts (3 posts)

  1. kanjipad
    Member
    Posted 1 year ago #

    I have replaced the Mingle forum header with a small sidebar widget that has links to:

    http://mysite.com/forum/?mingleforumaction=shownew
    http://mysite.com/forum/?mingleforumaction=editprofile&user_id=1
    (where user_id is appropriately adjusted)
    and
    http://mysite.com/forum/?mingleforumaction=profile&id=1
    (where id is appropriate to the logged in user)

    The first of these links loads a table showing new posts, exactly as the equivalent link does in the default Mingle Forum header.

    What I would really like is a way to gray out this link if there are no new posts, and change the mouseover text to indicate the number of new or unread posts. This would save the user from clicking the link only to find there are no new posts.

    I suspect the answer is somewhere in mingle-forum/wpf.class.php but going through someone else's code is tricky. I assume I would need to go through the same process Mingle uses to create the table, but count the number of new posts instead of outputting them into a table.

    Can anyone here provide some guidance? Is there some pre-written WordPress code I could use to get number of posts since a certain date/time?

    Thanks,

    Craig.

    http://wordpress.org/extend/plugins/mingle-forum/

  2. kanjipad
    Member
    Posted 1 year ago #

    Actually, I am close to solving this myself, based on other non-Mingle threads. The following code works out the number of posts (non-forum posts?) in the last day:

    $allDay = date('Y-m-d H:i:s', strtotime('-1 day'));
        global $wpdb ;
        $numpost = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND post_date > '$allDay'");

    I could probably attempt something similar with the Mingle posts.

  3. kanjipad
    Member
    Posted 1 year ago #

    This seems to work:

    global $mingleforum;
       global $wpdb ;
       $lastvisit = $mingleforum->last_visit();
       $threads = $wpdb->get_results("select distinct($mingleforum->t_threads.id) from $mingleforum->t_posts inner join $mingleforum->t_threads on $mingleforum->t_posts.parent_id = $mingleforum->t_threads.id where $mingleforum->t_posts.date > '$lastvisit' order by $mingleforum->t_posts.date desc");
       $num_new_posts = count($threads, 0);

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic