I'm using Views to display a table on a page with the data based on arguments passed via the URL. (The arguments are Taxonomy terms.)

What is the easiest way - using PHP if necessary - for me to change the page title to reflect the selected argument passed via the URL. For example, when someone goes to the page with all the types of shoes listed on it, the page title would become shoes.

Thank you.

Mitch

Comments

merlinofchaos’s picture

Status: Active » Fixed

In the 'title' field of teh argument, you can use %1, %2, %3 (etc) to put the argument used in the title.

mwander’s picture

merlinofchaos,

As you can probably guess, I'm a bit new to this - and trying to maximize my use of Views.

Is it possible for you to explain this a bit differently or in more detail, please? I've read all the Views documentation. I understand how to obtain arguments from the URL - and am doing that for the Taxonomy terms.

I'm not sure what to do in order to set the page title, Do I need to add code somewhere?

Thank you for your patience with me.

Mitch

add1sun’s picture

mwander I'll take a crack it. If you look at the Title field in your *Page* section of editing the view you will see it says this: "The title that be shown at the top of the view. May be blank. This title ignores arguments; if you want your title to take arguments into account, use the "title" field in the arguments section."

So, what you need to do is go down to the *Arguments* section and in the argument's Title field you would put %1, %2 or whatever. You can even include other text here so you could have the Title say "All about %1" (without the quotes) or whatever.

mwander’s picture

add1sun,

Works like a charm. Got it. Thank you!

And, I'm sure merlinofchaos appreciates that you resolved an issue on his behalf. :-)

Thanks again!

Mitch

Anonymous’s picture

Status: Fixed » Closed (fixed)
niklp’s picture

Version: 5.x-1.6-beta5 » 5.x-1.6
Status: Closed (fixed) » Postponed (maintainer needs more info)

This is grand, and works just fine - however, whereas my previous text-based title appeared in the breadcrumb trail, the argument-defined one now does not...

Is this by design, or what? Or is there another way to set them...?

merlinofchaos’s picture

The title being used for the current page shouldn't appear in the breadcrumb trail. The title for the page above (i.e, with no argument) should appear in the breadcrumb trail.

So if you put a title in the regular title section, and have 1 argument; if you go to that page without an argument, that's the title you'll get. If you go to the view iwth an argument, you should get the link to the page we were just on in the breadcrumb trail. If you do not something isn't working right.

(Note that setting the argument default to 'page not found' will eliminate it from the breadcrumb trail again, since it tries not to link to a nonexistent page.)

michelle’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Answered by merlinofchaos 2 months ago and no further questions added. Closing.

Michelle

doublejosh’s picture

This (fairly straight forward and long standing) technique has stopped working for me :(
The argument title in view in "Gallery %1", while using Taxonomy Term, and out comes "Home" as the title. Wacky.
I am using Page Titles module, but that hasn't caused a problem in the past.

How might I track down what is robbing me of my nice views arg titles or if there is a bug?

PS: I tried to use this snippet to solve the problem for a bit, however the title is still not able to be set here... even though I've confirmed the arg is being collected and is ready to go.

$view = views_get_current_view();
$args = $view->args;
// print_r($view->args);
$title = 'Gallery : '.$args[0]; // %1
drupal_set_title($title);
michelle’s picture

I would try disabling page titles to see. That module causes that same "Home" problem with CTools so it wouldn't surprise me if it was at fault.

Michelle

doublejosh’s picture

Thanks Michelle. That did it, however I have definitely had Page Title work fine with Views arg titles on other sites.

I thought it might be a weight issue, but Page Title = 0 and Views = 10, so views should be able to set the title after.

Guess it must be a third module that caused the problem between those two???

Bummer.

Appropriate titles is definitely more important than easy to configure spacers and title order, so page titles will have to go for now.

doublejosh’s picture

Found out this was fixed in Page Title 6-2.3 here: http://drupal.org/node/529186

Turns out it was a Token caching issue. It grabbed the cached token too soon.