Manually Constructing Links

12 posts by 3 authors in: Forums > CMS Builder
Last Post: May 10, 2010   (RSS)

By mark99 - May 4, 2010 - edited: May 4, 2010

Quick question, I need to link from one viewer detail page to another.

In other words I need to construct a link on this page..

cat_detail.php?NAME-OF-CAT-1

That takes me to this page (same title and record number but the two DETAIL pages interface to different category/fields and templates).

big_cat_detail.php?NAME-OF-CAT-1

The problem is the NAME-OF-CAT-1 part, well doing the NUM (record number 1) is easy enough but I cannot find an output for Name-of-Cat with the DASHES between each word. It's easy to do this if the title is just a single word/name but once you add space for multiple word titles then you cannot use a 'title' field call because it has spaces rather than dashes between the words.

So right now all I can make is links like NAME OF CAT-1 when what I want is NAME-OF-CAT-1.

Re: [gkornbluth] Manually Constructing Links

By mark99 - May 6, 2010

I tried this on my Detail Viewer page and it just returned the title with a space as normal:

<?PHP
$big_catsRecord['title'] = preg_replace("/[-]/", "&nbsp;", $big_catsRecord['title'] );
echo $big_catsRecord['title'];
?>

My title was (example) Super Minx and the result: Super Minx , not Super-Minx as I had hoped.

Re: [mark99] Manually Constructing Links

By mark99 - May 6, 2010

Ah this worked..

preg_replace("/[ ]/", "-",

Re: [mark99] Manually Constructing Links

By gkornbluth - May 6, 2010

Glad you got it going.

Jerry
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Manually Constructing Links

By mark99 - May 6, 2010

Yep, of course now I need to figure out how to add that part into my links.

$test1 = $big_catsRecord['title'] = preg_replace("/[ ]/", "-", $big_catsRecord['title']);
$test2 = $big_catsRecord['num'];

$my_output = str_replace("Big Cats", '<a href="**************/Big_Cat_Detail.php?">Big Cats</a>', $my_content);

I obviously need to stick $test1 and $test2 after ..php? in the ahref.

Hmm I'll probably also need to define an array to handle outputs with multiple categories and str_replaces [crazy] .

Re: [mark99] Manually Constructing Links

By gkornbluth - May 6, 2010

It might be easier than you think.

Here's another excerpt from my CMSB Cookbook http://www.thecmsbcookbook.com that may help to get you going;

DISPLAY LINKS ON YOUR WEB PAGE WITHOUT ERRORS
Here’s how to make sure that your URL’s work, even if the person entering the information doesn’t enter http://

Note: The solution in this recipe is not case sensitive. This means that if you’ve entered HTTP:// , or Http:// the code will still work.

In this example the field containing the URL is called web_site_link_url
and the field containing the link text is called web_site_link_text

If a URL doesn’t start with http:// the link will display incorrectly and won’t work. The if statement checks to see if the URL starts with http:// and if not, it adds that to the beginning of the URL

So, for a multi-record list viewer, you’d put the if statement before the link code in the viewer like this:
<?PHP if (!preg_match("/^http:\/\//i", $record['web_site_link_url'])) {
$record['web_site_link_url'] = "http://" . $record['web_site_link_url']; } ?>

<?PHP endif ?>

<a href="<?PHP echo $record['web_site_link_url'] ?>"><?PHP echo $record['web_site_link_text'] ?></a>


And for a detail viewer:

<?PHP if (!preg_match("/^http:\/\//i", $yourRecord['web_site_link_url'])) {
$yourRecord['web_site_link_url'] = "http://" . $yourRecord['web_site_link_url']; } ?>

<a href="<?php echo $yourRecord['web_site_link_url'] ?>"><?php echo $yourRecord['web_site_link_text'] ?></a>


Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Manually Constructing Links

By mark99 - May 6, 2010 - edited: May 6, 2010

I'm not sure that's quite what I'm looking for.

You see I have a DETAIL VIEWER page for each of my categories..

e.g.

big_cats_detail.php

small_cats_detail.php

Now on each of these individual pages I output a list of related categories e.g. "Big Cats, Small Cats" (exactly like that, without the speechmarks.. obviously).

So to link with each of these what I've been asking for above is to construct a URL that will allow me to add links like this..

http:/small_cats_detail.php?The-Minx-1

[url "http://www.interactivetools.com/forum/forum.cgi?url=http%3A%2F%2Fwww.interactivetools.com%2Fforum%2Fforum.cgi%3Furl%3Dhttp%253A%252F%252F%252A%252A%252A%252A%252A%252A%252A%252A%252A%252A%252A%252A%252Fbig_cats_detail.php%253FThe-Minx-1"]http:/big_cats_detail.php?The-Minx-1[/#0066cc][/url]

With your help I can now convert the TITLE field into "The-Minx" and then adding "-1" (i.e. from the record NUM field) should allow me to complete an automatic URL once I figure out how to construct the TITLE and NUM into a single URL after the big/small_cats_detail.php? part (see above two examples). So I cannot use any CMSB fields except the converted TITLE and of course NUM. Now I just need to figure out how to add those two bits on to the end of my URL and then find out how to do a str_replace for several different category titles to automatically link them with the modified URLs.


In other words the end result would be "Big Cats, Small Cats" displaying with automatic links to the related URLs above.

Re: [mark99] Manually Constructing Links

By mark99 - May 6, 2010

Made some progress by using this:

$urltest1 = "<a href=[url "http://www.bleh.co.uk/ISP_Detail.php?num-"]http://www.bleh.co.uk/ISP_Detail.php?num-[/#0066cc][/url]"."$numx".">"."Testing"."</a>";
$urltest2 = "<a href=[url "http://www.bleh.co.uk/ISP_Detail.php?num-"]http://www.bleh.co.uk/ISP_Detail.php?num-[/#0066cc][/url]"."$numx".">"."Testing2"."</a>";
$my_output = str_replace("Testing", "$urltest1", $my_content);

Of course the problem with this is that I can only use $my_output once, again meaning I need an array for "Testing","Testing2" but I have no idea how to plug one into this.

Re: [mark99] Manually Constructing Links

By Jason - May 7, 2010

Hi,

So, if I understand your problem correctly, you load a page, ex: cat_detail.php?NAME-OF-CAT-1
and on that page you want to construct a link to
big_cat_detail.php?NAME-OF-CAT-1.

Is that right?

It looks there may be an easier way to do this, since all you're trying to do is append a query string (everything after the "?" ) to the end of the another url.

Try something like this:

<a href="big_cat_detail.php?<?php echo @$_SERVER['QUERY_STRING']?>">Big Cat Detail</a>

This will take the string "NAME-OF-CAT-1" (or whatever the current query string happens to be) and append it onto the end of our new link (big_cat_detail.php?NAME-OF-CAT-1). All of the dashes will still be in place.

I hope that helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/