Search

bbPress Showcase » Plugins by Others

bb-topic-views small update...

RSS
  1. Kostya
    User has not uploaded an avatar

    new member
    Joined: May '08
    Posts: 2

    offline

    Hello, I came here from http://bbpress.org/plugins/topic/bb-topic-views/ because you suggest there a new way to show view count. But I can't get it to work.

    First you have this code:


    function forums_views_append($forums) {
    global $bbdb; $sum_meta_value="SUM(meta_value)";
    $forums_views = $bbdb->get_results(" SELECT $sum_meta_value,forum_id FROM $bbdb->topicmeta LEFT JOIN $bbdb->topics ON $bbdb->topicmeta.topic_id = $bbdb->topics.topic_id WHERE $bbdb->topicmeta.meta_key='views' GROUP BY $bbdb->topics.forum_id");
    foreach ($forums_views as $forum_views) {$forums[$forum_views->forum_id]->views=$forum_views->$sum_meta_value; }
    return $forums;
    }
    add_filter('get_forums','forums_views_append');

    Where do I add that? To bb-topic-views.php?

    And then I have to add to front-page.php template this: <?php echo $forum->views; ?>

    I suppose that should replace <?php show_view_count(); ?> from the original plugin?

    I'd like to figure this out since I do need and want to display views for topics but on my forums front page alone it generates 30 queries and I'd like to lower that number. Any help is appreciated, thanks!

    Posted 5 years ago #
  2. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 900

    offline

    The code I posted is to add total views for each forum, not for each topic which is already done. If you are getting extra queries, try bypassing the show_view_count entirely and display each topic's count via:

    <td class="num"><?php echo bb_number_format_i18n($topic->views); ?></td>

    I actually included the code for forum views in the "My Views" plugin in the "most-least-viewed" module. However you can make your own plugin with just this code if you'd like:

    <?php
    /*
    Plugin Name: Forum Views
    */
    function forums_views_append($forums) {
    if (is_front() || is_forum()) {
    global $bbdb, $forums_views; $sum_meta_value="SUM(meta_value)";
    if (!isset($forums_views)) {
    $forums_views = $bbdb->get_results("SELECT DISTINCT forum_id, $sum_meta_value FROM $bbdb->topicmeta LEFT JOIN $bbdb->topics ON $bbdb->topicmeta.topic_id = $bbdb->topics.topic_id  WHERE $bbdb->topics.topic_status=0 AND $bbdb->topicmeta.meta_key='views'  GROUP BY $bbdb->topics.forum_id");
    } foreach ($forums_views as $forum_views) {
    if ($forum_views->forum_id) {$forums[$forum_views->forum_id]->views=$forum_views->$sum_meta_value;}
    }
    }
    return $forums;
    }
    add_filter('get_forums','forums_views_append');
    ?>

    You'd have to put that into a file (ie. forumviews.php) into your my-plugins directory.

    But if you don't want total forum views you don't need that.

    This is a demo of the bbPress Signatures plugin!
    If you use my plugins, please considering donating to help continue their development.
    Posted 5 years ago #
  3. Kostya
    User has not uploaded an avatar

    new member
    Joined: May '08
    Posts: 2

    offline

    <?php echo bb_number_format_i18n($topic->views); ?>

    Very nice, 30 queries less now. Thanks.
    Now I have to figure out why its loading slower since I upgraded from 0.8 version of bbpress. Load time goes from 0.119 to 0.449 when I switch from default theme to mine I guess I messed up something.

    I tried your benchmark plugin and the load times for queries and they are both the same, but page load times are different.

    Posted 5 years ago #
  4. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 900

    offline

    bb-benchmark breaks down the render time vs query time. So you are saying query time is the same but the remaining render time is far higher? Interesting. Are you on a host like dreamhost where they use a NFS filesystem (remote storage). Because that will screw up anything that needs a large number of files to render.

    There might also be an issue with the javascript that 0.9 uses - I discovered someone has it loading prototype and jquery at the same time which is insanity. See if your page loads times suddenly become far faster if you either disable javascript on your browser temporarily.

    But if it's in the render itself, javascript won't be the cause, so you must have something in your templates. See if the increase happens on every page type or just something like the front page.

    bb-benchmark puts in your "view source"
    time to reach each section
    so look carefully at the header.php and footer.php times
    for the default vs your template and see which part radically increases.

    Posted 5 years ago #

RSS feed for this topic

Post a reply to “bb-topic-views small update...”

You must log in to post.

keep _ck_ coding >> donate $5 <<     Theme Switcher:
28 users online from in the past 30 minutes. 6 bots 22 guests
2,825 views today 8,118 yesterday 89,978 peak. Most at once 62 today 51 yesterday 539 peak. Visited today: mulli, rakesh
2,408 posts in 414 topics over 78 months by 445 of 2,509 members. Latest: elena0429, dancome89, adyante