Jump to content

Pages With Spaces in title


davo
 Share

Recommended Posts

I've made  a listings site which lists a number of towns. Each town is a page and the title of the page is the town's name. The problem I have is some of the towns have spaces in the names. When these are listed off, if you click them, the url takes you back to the home screen. If I add an underscore in place of the space, they work fine. Is there a work around for this please?

<?php

$county = $input ->urlSegment1;

    $towns = $pages->find("template='town',County=$county");
    foreach($towns as $c){
        $list_count = $pages->count("template='listing',town_select={$c->title}");
        echo "<li><a href='http://www.garagesalefinder.co.uk/listing-parent/{$c->title}'>{$c->title} ( $list_count ) </a> </li> ";
 }

?>

Link to comment
Share on other sites

Hi davo,

You should be using the name of the page, rather than the title, in the URL, eg:

echo "<li><a href='http://www.garagesalefinder.co.uk/listing-parent/{$c->name}'>{$c->title} ( $list_count )</a></li>";

Or alternately, so long as your page structure matches your URL structure, which is should unless you have done something unusual, you can simply use:

echo "<li><a href='{$c->url}'>{$c->title} ( $list_count )</a></li>";
Link to comment
Share on other sites

Hi davo,

You should be using the name of the page, rather than the title, in the URL, eg:

echo "<li><a href='http://www.garagesalefinder.co.uk/listing-parent/{$c->name}'>{$c->title} ( $list_count )</a></li>";

Or alternately, so long as your page structure matches your URL structure, which is should unless you have done something unusual, you can simply use:

echo "<li><a href='{$c->url}'>{$c->title} ( $list_count )</a></li>";

Perfect - and thanks for the second tip ; makes perfect sense.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...