By mactoph on
I have set up a view with an argument so that when someone types in http://www.myurl.com/view-name/argument it will display my posts tagged with the term 'argument' in that view. This is working fine.
However, when the argument is made up of two words, I am having trouble. It works, but I have to use an actual space in the url, e.g. http://www.myurl.com/view-name/argument%20argument
I would like to try to set it up so that the URL could instead be http://www.myurl.com/view-name/argument-argument and pull up the posts tagged with that two word term. Doable?
Is there a way that I can use the 'Argument Handling Code' to do this?
Any help or direction is greatly appreciated.
Comments
I'd be interested in this. I
I'd be interested in this. I think you could make a path alias for each views argument, but I don't know of a way to do it in views itself.
...
Replacing all '-' with ' ', in the arguments, is easy (yes, you can use 'Argument Handling Code'). One problem is that if you have a term named 'hi-fi equipment', and you put 'hi-fi-equipment' in your URL, then after cleaning all the '-'s you'd get 'hi fi equipment', which is a non-existing term.
You can try the folowing code (in 'Argument Handling Code'), which still lets you use spaces in the URLs (for the 'hi-fi equipment' cases):
(I haven't tested this.)
An easier option might be
An easier option might be simply to replace spaces by '+' symbols in your link generating code i.e.: example.com/view/taxonomy+term
- the +'s are converted into spaces for you.
:-)
That's correct :-)
Sometimes the reality is too simple..
True, Keep it
True, Keep it Simple
----
Darly
A + sign in the url is not
A + sign in the url is not appropriate as a replacement for spaces, only a hyphen should be acceptable.
Follow up
Thanks for the help- I think I have confused the issue though. What I would like to do is replace the ' ' (space) in the URL with a '-' hyphen.
In my case, the term at the end is the name of a US State, so urls such as /viewname/idaho work fine, but I have to use /viewname/new york or /viewname/new%20york/ to get the names with two states to work. I am hoping to be able to use the URL /viewname/new-york
I'm afraid I'm in a bit over my head here on this- any chance someone could throw out another snippet that I could put in the Argument Code section of the view?
solved
Thanks for the help above, I was confused for a little bit on which way the argument was being passed. I was able to solve the problem with this code in argument code section of my view:
Term with hyphen not working: update with strange url working..
Hi,
I have the same sort of issue, but my term itself is with a hyphen ('-').
My view and panel works great without hyphen, see: http://www.gratis-informatie.nl/over/parijs/frankrijk
but with hyphen (the hyphen is in my term itself, the view/panel doesn't work: see:
http://www.gratis-informatie.nl/over/alpe-dhuez/frankrijk .. is not working
parijs and alpe-dhuez are both terms, and the only difference is the hyphen ('-') between the two words.
I need to be able to have terms with an hypen, so getting writ of it is no option for me.
Update: I got it working with the following url: http://www.gratis-informatie.nl/over/Alpe+d%27Huez/frankrijk
How can I get the %27 out of the url please?
Thanks in advance,
greetings,
Martijn
How would you just remove
How would you just remove the space
$args[0] = str_replace('', ' ',$args[0]);does not seem to work & I want everything in onelongstring.
switch
Hampshire- Try this:
Nope, for some reason that
Nope, for some reason that doesn't work even though everything I have read says it should. It seems that my arguments are being read sort of backwards. For example if I wanted to take domain.com/category/term 1 and turn it into domain.com/category/term-1 I would need to use
$args[0] = str_replace('-', ' ',$args[0]);instead of
$args[0] = str_replace(' ', '-',$args[0]);Does anyone have any clue what could be causing this or that they were able to remove spaces.
Thanks for the reply
Yes same for me, it seems to
Yes same for me, it seems to be backwards. I even checked the manual incase I was getting it wrong http://au.php.net/str_replace
using - urls in stead off + urls
I had a problem using views. It forced me to use + signs in the url when using taxonomy terms with spaces in them as arguments. I solved the problem by putting the following code in the Argument Handling Code section of the view:
This will take the any - out of the argument part of the url and replace it with a space. This complements the default behavior of replacing any + with a space. This default behavior will still work (you can use both - and + urls).
Refer to #303800: Term ID
Refer to #303800: Term ID converted to name URL: spaces and special characters for a Views2 patch.
-thePanz-