Home arrow Site Administration arrow Page 6 - Building a Barebones Content Management System: The Yaapi API

yaapi - Display List Of Categories - Administration

This article will show you how to use the different API methods of yaapi, which is an API tool useful for managing content. It will explain how to retrieve a list of articles, display an article on a web page, retrieve a list of categories, and more.

  1. Building a Barebones Content Management System: The Yaapi API
  2. Under The Hood
  3. yaapi -- Getting Started
  4. yaapi -- Listing Articles
  5. yaapi -- Display An Article
  6. yaapi - Display List Of Categories
By: Harish Kamath
Rating: starstarstarstarstar / 6
September 21, 2005

print this article



One final bit before I drawn the curtains on this part of the series: I would like to update my application to display a list of categories in the left hand side menu, which was thus far populated with a bunch of static links. This is what I want it to look like:

Fortunately, yaapi comes to my rescue once again. This time it is the turn of the get_categories() method of the article() class that comes in handy. Since I need to display this menu on every page, it is only logical that I encapsulate the code that lists the categories in a separate function that can be invoked along the lines of my custom number_of_elements() function, listed earlier.

This is what my custom function, titled render_lhs_menu() and defined in the "inc.config.php" file, looks like:


// snip

// function to display the left hand side menu
function render_lhs_menu($article) {

 $return_value = "";
 $categories = $article->get_categories();

 for ($count = 0; $count < count($categories); $count++) {

  $return_value .= "<P><A HREF=\"category.php?id=".$categories[$count]['id']."\" >".$categories[$count]['name']."</A></P>";

 return $return_value;

// snip


There is no rocket science here. The function accepts an instance of the yaapi article() object as an input parameter and retrieves all the categories by calling the get_categories() method. As you may have guessed, this function returns an associative array containing the id and name of each category in the database. It concatenates the required HTML output as it iterates over the array and returns a string value to the calling script (say "article.php"), which in turn echoes it to the browser, as you can seen below.


// snip

<TR HEIGHT="350">
   <?php echo render_lhs_menu($article);?>
   // snip


// snip


Finally, I have managed to make all components of my web page dynamic -- yes, I have excluded the footer section as it remains constant across most websites. You may argue that I could have defined another function to return the content for this footer section. Good point; I leave that as an exercise for you.


This brings me to the conclusion of the second part of the "Building a Barebones Content Management System" tutorial.

Let me quickly recap the topics that I covered today. Initially, I gave a detailed introduction to the different entities that drive yaapi. Next, I demonstrated how to retrieve a list of articles in a particular category as well as display the content of a selected article using the get_categories() and get_article() methods respectively. After that, I developed a custom function that returns the HTML code required to display the categories defined in yaapi. Finally, I have an application that fetches data from the database and renders it in a logical manner, as one expects from any program worthy of being called a CMS application.

In the next part, I shall introduce the patTemplate template engine. After demonstrating a few examples that show the versatility of this software API, I will integrate it with the PHP scripts listed today, thereby bringing me closer to fulfilling my goal of developing my barebones CMS.

Till then, enjoy!

>>> More Site Administration Articles          >>> More By Harish Kamath

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Coding: Not Just for Developers
- To Support or Not Support IE?
- Administration: Networking OSX and Win 7
- DotNetNuke Gets Social
- Integrating MailChimp with Joomla: Creating ...
- Integrating MailChimp with Joomla: List Mana...
- Integrating MailChimp with Joomla: Building ...
- Integrating MailChimp with Joomla
- More Top WordPress Plugins for Social Media
- Optimizing Security: SSH Public Key Authenti...
- Patches and Rejects in Software Configuratio...
- Configuring a CVS Server
- Managing Code and Teams for Cross-Platform S...
- Software Configuration Management
- Back Up a Joomla Site with Akeeba Backup

Developer Shed Affiliates


Dev Shed Tutorial Topics: