close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

How to make details page link have title of the page instead of number ie ?id=1,2,3.......

Thread began 9/13/2014 3:23 pm by Kumel | Last modified 12/29/2014 12:23 pm by Kumel | 4992 views | 25 replies

Jamie

Hey Kumel

I thought I would create a tutorial for this so have written it up (tutorial not yet submitted) but hopefully this will help you. I have had to make certain assumptions so if any step needs clarification please drop me a line.

In the first place you need to add a new column to your 'blog' table - lets call the new column 'Permalink' and set it to varchar like you have set the 'title' column.

Permalink will store the SEO friendly part of the URL and we will get the _insert or _results pages to change a title from this format 'This is the blog title' to 'this_is_the_blog_title' - you can see an example of that here http://www.motley.co.uk/blog-article/Dont-let-bootstrapping-lead-to-handcuffing

Once you have added that column to the table, we need to open up the blog _insert and _update pages (I am not sure what you have named them)

On the _update page you need to click on 'Update Record' that you find in the server behaviours area. In the resulting Data Assist pop up window you should have 2 tabs: General and Bindings - click on 'Bindings' and look for the column named 'Permalink' that we created at the beginning. When you find it, highlight it, set the type to 'text' and then click on the lightning bolt. A new window will open which allows you to bind the form elements to the relevant columns. Bind the entry called 'title' (using your column name) - when you select the binding it should look like this <?php echo((isset($_POST["title"]))?$_POST["title"]:"") ?>

Click OK, and then OK again

Now, in the code view of the page you need to navigate to the Update Record which you can get to quickly by clicking the same in the server behaviours. In this area there will be 2 instances of the following:

$WA_AB_Split . "".((isset($_POST["title"]))?$_POST["title"]:"")  ."" .



change the 2nd instance to this:

$WA_AB_Split . "".((isset($_POST["title"]))?preg_replace('/[^0-9a-z(),]/i','-',str_replace(array("’ ","br ","<",">","' ","%","!","?","@","\-","- ","/ ",".","\"","_","– ","\'","*","#","+ "),"",strtolower(stripslashes(str_replace("&", "and", str_replace("é", "e", $_POST["title"])))))):"")  ."" .



This is basically to take whatever the user enters in as a title (eg This is a blog post) and changes it to this_is_the_blog_post

Now you need to do the same for the _insert page. (Update Record will be Insert Record etc)

The back end is now all set and we just need to address the .htaccess file which does the mod_rewriting and change the front end so that the new SEO friendly URL will display instead of ?id=1,2,3....... etc

In the front end you should have 2 blog pages. One shows the results of all blog posts (lets call this one blog.php) and the other is the one that displays the content of each blog article (lets call this one blog-article.php)

Lets open up blog.php.

Here I am making the assumption that your recordset is named 'Blog' - if it isnt, just change the rs references to whatever you have called it.

On blog.php we need to change the link structure from something that looks like this:

<a href="blog-article.php?BlogID=<?php echo($Blog->getColumnVal("BlogID")); ?>"> <?php echo($Blog->getColumnVal("BlogTitle")); ?></a>



the onpage url structure for the above would be /blog.php?BlogID=1,2,3...etc

to this:

<a href="article/<?php echo $Blog->getColumnVal("Permalink"); ?>"> <?php echo $Blog->getColumnVal("title"); ?></a>



the onpage url structure for this would look something like this /article/this_is_a_blog_post

Now lets open up blog-article.php

On this page we need to change the recordset so that the page is able to render the correct page based on the mod_rewrite that we will be doing in the .htaccess file at the end of this.

The recordset that you use to access the blog data needs to loo like this:
(if you're using MySQLi)

<?php
$Blog = new WA_MySQLi_RS("PageContents",$DBConnection,1);
$Blog->setQuery("SELECT * FROM blog WHERE id = ? OR Permalink = ?");
$Blog->bindParam("i", "".(isset($_GET['id'])?$_GET['id']:"") ."", "-1"); //paramOffersID
$Blog->bindParam("s", "".(isset($_GET['perm'])?$_GET['perm']:"") ."", "-1"); //paramPermalink
$Blog->execute();
?>



(if you're using MySQL)

<?php
$colname_BlogPerm = "-1";
if (isset($_GET['perm'])) {
$colname_BlogPerm = $_GET['perm'];
}
$colname_Blog = "-1";
if (isset($_GET['id'])) {
$colname_Blog = $_GET['id'];
}
mysql_select_db($database_PowerCMSConnection, $PowerCMSConnection);
$query_Blog = sprintf("SELECT * FROM blog WHERE id = %s OR Permalink = %s", GetSQLValueString($colname_Blog, "int"), GetSQLValueString($colname_BlogPerm, "text"));
$Blog = mysql_query($query_Blog, $PowerCMSConnection) or die(mysql_error());
$row_Blog = mysql_fetch_assoc($Blog);
$totalRows_Blog = mysql_num_rows($Blog);
?>



Also on the blog-article.php page because we are changing the directory structure on the fly, we need to tell the page what the root of the site is so that it is able to reference all the files correctly. To do this, add this just after the opening <html> tag

on a local server: <base href="http://localhost/foldername/" />
on a live page: <base href="http://www.domainname.co.uk/" />

don't forget the trailing / in either of those examples

Save the blog.php and blog-article.php pages if you havent already done so.

Now we need to create the rewrite in the .htaccess file.

All you now need to do is create (or edit if you already have one) using the following code.

RewriteEngine on

RewriteRule ^article/(.*)$ blog-article.php?perm=$1 [NC,L,QSA,T=application/x-httpd-php]



Save and upload

Save that and now upload all the files and you should have a similar set up to the one found at http://www.motley.co.uk/blog.php

I hope that this helps but if you need any help or clarification please do let me know

All the best

Jamie

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...