Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Retrieving Data from MySQL and Displaying in Main Content Area

I need help in adding some content to my home page. I've set categories as the home page for my blog. Now I want to manually edit the template and show 10 popular discussions (base on views) above the list of categories. I'll be really glad if someone can guide me on how to achieve this? What query to write and how to get the data to display?


Best Answers


  • Options

    @kasperisager this is very helpful. Where should I place this function and how will it display the list? Please help...

  • Options
    KasperKasper Scholar of the Bits Copenhagen Vanilla Staff

    I'd suggest copying @peregrine's MostPopular plugin and hacking it to suit your needs.

    Kasper Kronborg Isager (kasperisager) | Freelance Developer @Vanilla | Hit me up: Google Mail or Vanilla Mail | Find me on GitHub

  • Options

    Ok, I'll try that. Currently if I place the contents of this function in a view file, and try to do Num Rows as $NumRows = $PopCommentData->NumRows();

    I get the error: Fatal error: Call to a member function NumRows() on a non-object

    Why does that happen?

  • Options

    you are probably should checkout how the discusssion model does it, as the example above only gives a small amount of info and doesn’t join the users.

    you would need to make use of a controller hook to do the query, such as CategoriesController_Render_Before and use to pass the data to a view hook

    this uses some view hook to insert a view with this in

      <ul class="DataList Discussions">
         <?php include($this->FetchViewLocation('discussions', 'discussions')); ?>

    would give you a standard discussion list, note it will make use of ->DiscussionData which is the result of you query, therefore if the controller is already using it for some other resultset, you need to ensure the two resultsets don't get mixed up.

    I think that is about all the help I can reasonably give you.

    grep is your friend.

  • Options

    Thank you so much. I took the MostPopular plugin and that is helpful.

    In that plugin, my main confusion now is how to display the data retrieved only on the categories page, which is my home page now, and I want to display it above the list of categories.

    Currently the plugin is set to display the data in Panel. I can change AssetTarget to 'Content' which makes the data shift to main area but it will still be on all pages and below the discussions.

  • Options
    x00x00 MVP
    edited February 2013

    note the bit that says Base_ change it to CategoriesController_ in default.php

    grep is your friend.

  • Options

    Thank you @x00

    I'm going to make all changes per my requirement and post my success here.

    And why $ShowOnController array has discussioncontroller twice?

    One last question, how to make it show above the categories instead of below?

  • Options

    Friends, I've successfully implemented this on my website. Thanks for so much support!

Sign In or Register to comment.