Your first task is to create links that will allow you to edit and delete entries. You'll eventually want this to be available to administrators only (see Chapter 11 for more information on this topic), so you're going to build these links inside a function, rather than inline in index.php.
Name your function adminLinks() and have it accept two arguments: the current page ($page) and the URL of the entry you're working with ($url).
To start, open up functions.inc.php and declare your new function just below retrieveEntries():
function adminLinks($page, $url) { // Build admin links here }
The first step in your function is to build the addresses for your links. For your editing link, this address simply appends the entry's URL to the end, which you'll use later to identify the entry being edited. The path for the link follows this format:
/simple_blog/admin/page/url
The delete link works a little differently; rather than using the page, you use the word "delete" in the address, signifying that the entry is to be deleted. The delete link follows this format:
/simple_blog/admin/delete/url
Now it's time to add these paths to adminLinks() in functions.inc.php. Do so by inserting the lines in bold, as shown:
function adminLinks($page, $url) { // Format the link to be followed for each option $editURL = "/simple_blog/admin/$page/$url"; $deleteURL = "/simple_blog/admin/delete/$url"; // Finish the admin links here }
Finally you need to create the hyperlinks from your URLs and return them so they can be used in index.php. You need to place your links in an array, so that both the edit and delete links can be returned by your function. Add the bold lines to functions.inc.php:
function adminLinks($page, $url) { // Format the link to be followed for each option $editURL = "/simple_blog/admin/$page/$url"; $deleteURL = "/simple_blog/admin/delete/$url"; // Make a hyperlink and add it to an array $admin['edit'] = "<a href="$editURL">edit</a>"; $admin['delete'] = "<a href="$deleteURL">delete</a>"; return $admin; }
Now you can generate custom edit and delete links quickly for any entry with a URL (which, in your application, is all of them). Next, you need to display those links, as well as their corresponding entries, in index.php.