We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18397
    • 3,250 Posts
    For an upcoming releases, the team and I have concluded that NewsListing needs to be broken down into a class so that it can be re-used more easily. Here is an example of its use within a future version of NewsListing. Note that all of these functions can be controlled manually (instead of automatically using default values as in the example here).

    <?php
    
    // NewsListing Snippet --- Class Edition
    $output = "";
    
    $nl = new NewsListing();
    
    $currentPage = $_GET["currentPage"];
    	// make into an inline if when I get the chance
    	
    $parameters[] = array();
    	// array of parameters
    	// normally this would be full of all the normal parameters for NewsListing such as summarize, etc.
    	
    $nl->setParameters($parameters);
    	// send the properties to the class
    
    $nl->setTemplate($tpl);
    	// set and verify the template
    
    $nl->setFormat($format);
    	// set the output format: either html, rss, or podcast
    	
    $resources = $nl->getDocuments();
    	// retrieves the documents and puts fills the $resource array
    	
    $documents = $nl->parseDocuents($resources);
    	// sets $documents to an array of the parsed documents
    	
    $documents = $nl->sortDocuments($documents);
    	// sorts the documents array by the specified fields
    
    if($nl->parameters["paginate"] == 1) {
    	$documents = $nl->paginate($currentPage);
    	// paginates the documents array, autoinheriting the parameters that were sent to the class, sets placeholders for items, 
    }
    
    return $nl->generateOutput($documents);
    	// handles outputting headers for specified formats, and generating archives (if neccessary)
    
    // END SNIPPET
    
    ?>
    
      • 32241
      • 1,495 Posts
      Way to go Mark. There is nothing better than encapsulating all the workhorse inside a class, so it can be re-used without having to do sanity check first, except for when using require_once to include the class file.

      I believe the community are alooking forward to a more mature and flexible newslisting snippet/class.

      Sincerely,
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
        • 25663 MODX Staff
        • 12,272 Posts
        Anyone want to help do this with DropMenu... my how it’s needed!
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 18397
          • 3,250 Posts
          I bring good news to all those listening!

          NewsListing Class Edition parsed its first page today! It can now handle most basic NewsListing functions. Hopefully by the end of the week I’ll have it mostly complete!
            • 18397
            • 3,250 Posts
            Oh, forgot to mention the best part! I’ve cleaned up my code signifcantly so it is now 1/2 the size of its previous version. Additionaly, its 3/100th’s of a second faster!