List articles by topic

In this tutorial topic you will build the page that retrieves and displays the list of articles for a selected topic. This page is loaded when the user clicks on a menu link, and filters the articles by the topic ID passed as parameter. The list will display the article title, the first 100 characters in the article and a link to the full article.

The steps to create this page are:

Create the article recordset

To display the article list you must first retrieve information about existing articles from the database. The articles to retrieve must meet two conditions:

  1. First they must belong to the selected topic - the topic ID must match the passed URL parameter.

  2. The articles must have been already approved. Articles that are set as draft, or are in review must not be displayed.

To build this recordset you will use MX Query Builder (also known as QuB) which allows visual definition of queries:

  1. Open the article_list page in Dreamweaver.

  2. Go to the Bindings tab > Plus (+) >Recordset (Query).

  3. Now click on the QuB3 button to load the QuB Visual Recordset interface. Configure it as explained next:

  4. The main QuB interface is web based, and it loads inside your system default browser. All interface components are explained here.

  5. To create the recordset follow the next steps:

  6. When you are done setting up the options, in the Query menu select Save, then Close.

  7. Back in Dreamweaver, to use the query you've just created click the Refresh button. The SQL textarea (until now, empty) will display the SQL code for the recordset. Click OK to create it.


         

  8. The new recordset is displayed in the Bindings tab, and can be used like any other - you can drag its fields onto the page or double-click to edit it.

Display the article data

For the page to be enticing for the visitor, you will display the article title, the first 100 characters of the article body and a link to the article detail page:

  1. Drag and drop the title_art field from the Bindings tab onto the page. Select the dynamic text added to the page, and from the Format drop-down menu in the Property Inspector select Heading 3.

  2. Create a new paragraph after the title: place the cursor after the dynamic text and press Enter/Return.

  3. Drag and drop the content_art field from the Bindings tab in the newly created paragraph. This will result in displaying the entire article - not what is desired. To reduce the number of characters to display, you must make some changes:

  4. Create a new paragraph and type Read more. This will be the link to the article details page.
  5. Select the entered text and click the Folder icon next to the Link text box in the Property Inspector.
  6. Select the index page and click the Parameters button to define the URL parameters to pass. You will add two parameters - the article ID and the mod parameter:


                        
  7. Place the mouse cursor after the link. Go to the HTML tab of the Insert bar, and add a Horizontal Rule - the first icon on the toolbar. With the new rule selected, enter its Height in the Property Inspector H text box. Set it to 1 pixel:


                  
  8. Now the page displays information for the first article only. To display the remaining articles as well, you must apply a Repeat Region server behavior, in a similar manner to the menu page:

  9. The last thing you have to do to complete the page is to provide a fail-safe mechanism for when a topic does not contain any articles. This is done using two Dreamweaver server behaviors: Show If Recordset Is Empty and Show If Recordset Is Not Empty.
  10. Press Ctrl+A to select the entire page content. Go to the Server Behaviors tab > Plus (+) > Show Region and select the Show If Recordset Is Not Empty entry. In the dialog box that is displayed select the rsArticleList as the recordset to check:


                

  11. Next place the cursor after all page content, not only after the last text and type: This topic does not contain any articles yet!. Select the text and apply the Show If Recordset Is Empty server behavior from the Server Behaviors tab > Plus (+) > Show Region. Configure it as the previous one.

  12. In Dreamweaver, the page should now look like the image below:


              
    Note:
    The exact appearance depends on your particular server model.

Add the article list to the main layout

Before testing the page you must add it to the main page. Content on the main page is loaded dynamically, based on the mod URL parameter, with a Server-Side Includes From List server behavior. This server behavior allows defining a list of URL parameter values and filenames to load:

  1. Open the index page in Dreamweaver.

  2. Select the Content for id "content" Goes Here default text and remove it.

  3. Go to the Server Behavior tab > Plus (+) > MX Kollection > Server-Side Includes and select the Server-Side Includes From List entry.

  4. The user interface displays the existing included files in a list, and allows adding or removing items with the Plus (+) and Minus (-) buttons. To add a new entry, click the Plus (+) button, then define its properties in the fields below the list:


                 

  5. The user interface has a second tab - Parameter - where you can define the URL parameter name used to pass instructions to the dynamic include. By default it is set to mod, and this value will also be used throughout the tutorial.
    Note:
    If you want to use another URL parameter, change it on this tab of the user interface, and then replace it everywhere it is used in the tutorial.

  6. Click OK to apply the server behavior and close the user interface.

 

Save the page and press F12 to preview it in a browser. To try out the article list, select one of the menu topics - if it has articles, they will be displayed:

 

If you select a topic that does not contain any articles, the fail-safe mechanism will work, and you will see something similar to this:

 

When the index loads for the first time, or when no value is passed for the mod parameter, at this point you only see the menu, and blank space in the right. To correct this you must define another included file that will be displayed when no value for mod is passed:

  1. Double click the Server-Side Includes from List server behavior to edit it.

  2. In the Basic tab click the Plus (+) button to define a new included file. Configure the fields as follows:

  3. Click OK to apply the changes and close the user interface.

Now when you first load the site index you no longer get an empty screen, but a nice welcoming note:


 

In the next topic of the tutorial you will complete the application front-end by creating the article detail page and the main page.