Hand coded detail links and permalinks.
2 posts by 2 authors in: Forums > CMS Builder
Last Post: May 16, 2014 (RSS)
By rconring - May 9, 2014
Is it possible to programmaticaly create permalink URLs since I am not using the internally generated links (_link)? Using one index.php page, I pass several variables in the url in order to distinguish different styles and types of pages ... list or detail etc. Eg: /index.php?pg=3 would use page and sidebar elements for category 3 which includes a product list page. /index.php?pg=3&item=12 is the detail page for an item on page 3. The link is constructed programmatically from the list code as such:
<?php
$pname = str_replace(' ','-',$precord['name']);
$pname = strtolower($pname);
$prodLink = '/index.php?pg='.$precord['category'];
$prodLink .='&item='.$precord['num'];
$prodLink .='&'.$pname ;
?>
Then I am getting the variables from the URL with:
$pageNum = isset($_REQUEST['pg']) ? $_REQUEST['pg'] : null;
$detailNum = isset($_REQUEST['item']) ? $_REQUEST['item'] : null;
if(!$pageNum)$pageNum = 1;
I have all of this working well but before I go any farther with this concept, I need to know if the permalinks plugin is going to work with this concept in any way.
I guess what I am after is a way to manually access the permalinks database and create my own version of a cross reference.
Does any of this sound feasible?
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987
By gregThomas - May 16, 2014
Hi Ron,
With the permalinks you can still pass values into the URL, so you could have a permalink for the $prerecord record and pass in the category as well. For example, you could modify the code so that URL's look like this:
/this-is-a-permanlink?pg=4
You could set up the section that contains the records so that the list and detail pages are index.php. Then if you modified your link creation code to use the permalink and category like this:
$prodLink = '/'.$precord['_link'].'?pg='.$precord['category'];
When a permalink is used that links to a record, the num value is passed into the request array. So say my this-is-a-permalink permalink was for record 12 in a section called cars. Then $_REQUEST['num'] would be automatically set as 12 when the detail page loads. Then you could just modify your code so that instead for $_REQUEST['item'], it looks for $_REQUEST['num']:
$pageNum = isset($_REQUEST['pg']) ? $_REQUEST['pg'] : null;
$detailNum = isset($_REQUEST['num']) ? $_REQUEST['num'] : null;
if(!$pageNum)$pageNum = 1;
Let me know if you have any questions.
Thanks!
Greg
PHP Programmer - interactivetools.com