Announcement

Collapse
No announcement yet.

Random Article Widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [CMS] Random Article Widget

    How would I go about getting a random article widget?
    vBulletin Rules!

  • #2
    I would do it as a php direct execution. You could write your own widget if you were writing for distribution, but that would be significantly more work. You'd have to know, or have somebody who knows, how to write php code to pull records from the database. A couple things you have to know:
    1) Look in the contenttype table to get the article content type.
    2) Look in the node table with that content type to get the articles. You'll need nodeid and url to generate the proper SEO Url.
    3) Look in the nodeinfo table with that nodeid to get the title.

    And there are functions to help you generate the URL. Something like

    $route = vB_Route::create('vBCms_Route_Content');
    $route->node = $node['nodeid'] . (empty($node['url']) ? '' : '-' . $node['url']);
    $pageurl = $route->getCurrentURL();
    Please- I'm not tech support. Don't send your problem reports to me unless I've asked you to.

    Comment


    • #3
      I still haven't found anyone who can do this. Even a really simple version would be nice.
      vBulletin Rules!

      Comment


      • #4
        Edwin's told you all you need to know about it. You have to use PHP direct execution to query the article and display it.
        Owner: Oracle Forums - General Discussion Forums.

        Comment


        • #5
          That would be great if I knew how to do it. Do you think you could give it a shot?
          vBulletin Rules!

          Comment


          • #6
            Hmmm.. i may.... i am doing a lot of custom work these days.. but ill give it a shot next weekend after i finish my current work. I will put it up on vb.org if done.
            Owner: Oracle Forums - General Discussion Forums.

            Comment


            • #7
              I've been trying to do it through the comment forum somehow but I'm still stuck. Can anyone try and create this?
              vBulletin Rules!

              Comment


              • #8
                Remember there is a five minute cache, so it will be the same for that many minutes. This works for me in a quick test:
                $maxid = 40000;
                $article = false;
                $counter = 10;
                while(!$article )
                {
                //get a random number
                $id = rand(1,$maxid);

                $record = vB::$db->query_first("SELECT nodeid, publishdate, setpublish, userid,
                parentnode, permissionsfrom, hidden, contenttypeid FROM " . TABLE_PREFIX . "cms_node WHERE nodeid = $id" );

                //We need to verify that this is published and is not a section.
                if ($record AND $record['nodeid'] AND ($record['setpublish']) AND ($record['publishdate'] < TIMENOW)
                AND ($record['contenttypeid'] !== vB_Types::instance()->getContentTypeID("vBCms_Section")))
                {

                vBCMS_Permissions::setPermissionsFrom($record['nodeid'], $record['permissionsfrom'], $record['hidden'],
                $record['setpublish'], $record['publishdate']);
                if (vBCMS_Permissions::canView($record['nodeid']))
                {
                $class = vB_Types::instance()->getContentTypeClass($record['contenttypeid']);
                $package = vB_Types::instance()->getContentTypePackage($record['contenttypeid']);
                $article = vBCms_Content::create($package, $class, $record['nodeid']);

                if (method_exists($article, 'getPreview'))
                {
                $output = $article->getPreview()->render();
                return;
                }

                }
                }
                //just in case there's a runaway, we need to be able to break out of the loop
                if ($counter > 10)
                {
                break;
                }
                }
                $output = '';
                Please- I'm not tech support. Don't send your problem reports to me unless I've asked you to.

                Comment


                • #9
                  Hey can you explain that a little better? Where do I put that code? Does it show the article or a link to it? I just want to show a button that says "Random Article."
                  vBulletin Rules!

                  Comment


                  • #10
                    Originally posted by kontagio.us View Post
                    Hey can you explain that a little better? Where do I put that code? Does it show the article or a link to it? I just want to show a button that says "Random Article."
                    Thats the code for a widget.

                    Comment


                    • #11
                      Originally posted by kontagio.us View Post
                      Hey can you explain that a little better? Where do I put that code? Does it show the article or a link to it? I just want to show a button that says "Random Article."
                      Create a PHP Direct Execution widget and paste that code into the content block. Give it a name and save it. Put it on your layout. Test. If you don't like it, remove it.
                      Please- I'm not tech support. Don't send your problem reports to me unless I've asked you to.

                      Comment


                      • #12
                        Hey thanks that's exactly what I was looking for. Thank you so much man I've been looking for this since the CMS came out.

                        I was wondering if you could help me with some styling issues now.

                        Blue arrow: I have it set up as a section, can I make it show no "Primary Content"
                        Red arrow: The php code comes after the div or table. I'm not sure if this is in the code or the style. see yellow arrow.
                        Last edited by kontagio.us; Wed 21st Dec '11, 11:10pm. Reason: unlinked
                        vBulletin Rules!

                        Comment


                        • #13
                          The blue arrow- that's a phrase. Go into admincp > languages & phrases > search phrases. Search for that string, edit it, and put in whatever you like.


                          The red arrow- you'll have to experiment a bit. I would make a new template, but you can edit the current one if you prefer. Copy/paste the content from vbcms_widget_execphp_page, and assign that template to the widget. Then edit the template to something like:
                          <div class="cms_widget">
                          <div class="cms_widget_header">
                          <h3>{vb:raw title}</h3>
                          </div>
                          <div class="cms_widget_content">
                          {vb:raw output}
                          </div>
                          </div>

                          Depending on exactly how your css is set up, those cms_widget classes may be expendable. You may need to add some styling, like style="padding:0px" or something. But just removing one or two of the div's should make it better.

                          If you read my post on the new php executable content type, in v404 this will be a lot easier. You could put this code directly into the page, or render the current widget onto the page.
                          Please- I'm not tech support. Don't send your problem reports to me unless I've asked you to.

                          Comment


                          • #14
                            Hey it's not exactly what I'm looking for but it works perfectly. Thanks again for your help Edwin, my site wouldn't be half as cool without you.
                            vBulletin Rules!

                            Comment


                            • #15
                              Originally posted by kontagio.us View Post
                              Hey it's not exactly what I'm looking for but it works perfectly. Thanks again for your help Edwin, my site wouldn't be half as cool without you.
                              What's your url? Now i'm very interested^^

                              Comment

                              widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                              Working...
                              X