Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Display Title of Applicable Archive Page WordPress

  • SOLVED

Hi,
If someone is on the homepage, http://adgib.com/brian/bicycletourfinder/001/, and clicks on a taxonomy term like "Type of Tours -> Day AND City: Luang Prabang AND Country/Region: Laos AND Type of Tour: Day" and is taken to this page: http://adgib.com/brian/bicycletourfinder/001/?to-countries=laos&cities=luang-prabang&type-of-tours=day-bicycle-tours&attractions=angkor-wat
how do I display:
Angkor Wat | Luang Prabang | Laos | Day Bicycle Tours
at the top of the results page? (So it displays whatever terms were searched for?)

So far I have this in my functions file and it's not working:

add_action ('genesis_before_loop', 'taxonomy_page_title');
function taxonomy_page_title () {
if (is_tax()) {?>
<?php
echo '<h2 class="pagetitle">Archive for the ‘'.single_cat_title('',false).'’ Category</h2>';
?>
<?php }
else (is_page_template('single-btf-tour-operators.php')); echo '';
}


Thank you!

Answers (3)

2011-08-10

Joshua Nelson answers:

You can use the get_query_var() function to display these. For example:



if(get_query_var('attractions') != '') {
$attraction = get_taxonomy (attraction);
$attraction_term = get_term_by('slug', get_query_var('attractions'), attraction);
$attraction_name = $attraction_term->name;

echo $attraction_name;

}


You need to replace NAME with whatever you registered used as your taxonomy label variable when you registered it. If you have issues with this, just paste your taxonomy code and I can grab it. For instance, I assumed that the taxonomy is named "attraction" no "s", change that as necessary.

You should be able to copy that above code, changed for each taxonomy, and get them all to display. String them together in the format you like.


Daniella comments:

Now I have this:
add_action ('genesis_before_loop', 'taxonomy_page_title');
function taxonomy_page_title () {
if ( is_tax() ) {
if(get_query_var('attractions') != '') {
$attractions = get_taxonomy (attractions);
$attractions_term = get_term_by('slug', get_query_var('attractions'), attractions);
$attractions_name = $attractions_term->name;
echo $attraction_name;
}

}
else (is_page_template('single-btf-tour-operators.php')); echo '';
}


and it doesn't seem to be working. The taxonomies are:
'attractions'
'cities'
'to-countries'
'type-of-tours'

as I'm not sure how to string them together to output
Attraction | City | Region | Type Bicycle Tours


Joshua Nelson comments:

Ok, try this:


function taxonomy_page_title () {
if ( is_tax() ) {
if(get_query_var('attractions') != '' && get_query_var('cities') != '' && get_query_var('to-countries') != '' && get_query_var('type-of-tours') != '') {
$attractions_tax = get_taxonomy (attractions);
$attractions_term = get_term_by('slug', get_query_var('attractions'), attractions);
$attractions_name = $attractions_term->name;

$cities_tax = get_taxonomy (cities);
$cities_term = get_term_by('slug', get_query_var('cities'), cities);
$cities_name = $cities_term->name;

$countries_tax = get_taxonomy (to-countries);
$countries_term = get_term_by('slug', get_query_var('to-countries'), to-countries);
$countries_name = $countries_term->name;

$tours_tax = get_taxonomy (type-of-tours);
$tours_term = get_term_by('slug', get_query_var('type-of-tours'), type-of-tours);
$tours_name = $tours_term->name;

echo $attraction_name . " | " . $cities_name . " | " . $countries_name . " | " . $tours_name;

}
} elseif(is_page_template('single-btf-tour-operators.php')) {
echo '';
}



Let me know if you have any issues with that. If you do, please paste your register taxonomy code in your response and I'll see if there are any inconsistencies between that and this code.

You can also try adding

echo "testtest";

In the if statement section to make sure it's working.


Joshua Nelson comments:

Also, you need to be sure that the slug for the specific taxonomy (say Angkor Wat) is the same as the query variable ("angkor-wat") otherwise that code won't display the attraction name. Same goes for the others, you should have a city taxonomy saved with a slug matching the queried variable "luang-prabang"


Daniella comments:

That didn't work either. Ivaylo's code worked, though. I didn't look at the differences yet.


Joshua Nelson comments:

Great, his uses the proper hook for genesis and specifies if statements for each query variable....

Try this, modified from Ivaylo's modification of mine ;-)

http://pastebin.com/0qMjzP1Q


Joshua Nelson comments:

just updated that code, so you might want to check it again if you already grabbed it...


Daniella comments:

I pasted the code and received an error. Ivaylo's code worked, though.
Thank you.

2011-08-10

Ivaylo Draganov answers:

Hello,

It looks like this challenge is already solved in your theme. When going to the results page, the title of the page (I mean <title>) is already displaying:

<title>Attraction: Angkor Wat; Type of Tour: Day; City: Luang Prabang; Country/Region: Laos</title>


I'd suggest you dig inside the code that generates this title and use the same function or tweak it to be used as a title for the archive. It will be a better solution than writing a new function as you will reuse existing code.

I see that you are using Genesis but is it also responsible for the <title> tag? Or is it a custom function that you've added?


Daniella comments:

I thought that too but only found this and don't know how to implement it properly:
if ( is_tax() ) {
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

$title = ! empty( $term->meta['doctitle'] ) ? wp_kses_stripslashes( wp_kses_decode_entities( $term->meta['doctitle'] ) ) : $title;
}


Ivaylo Draganov comments:

This could be on the right path but it's not exactly what we're looking for. It's just not sufficient to create the whole complex title. Unfortunately I don't posses a copy of Genesis so I can't search for that function.

You can try something like this (based on Joshua Nelson's code above):
[[LINK href="http://pastebin.com/nYifJvbi"]]http://pastebin.com/nYifJvbi[[/LINK]]


Daniella comments:

That code worked almost perfectly. An issue I see now is if you only search for one term then the bars look terrible: http://adgib.com/brian/bicycletourfinder/001/type-of-tours/cross-country-bicycle-tours?to-countries&cities&attractions.
Any suggestions? Thank you!


Ivaylo Draganov comments:

Alright! Try the update version please. It should take care of the separators:
[[LINK href="http://pastebin.com/nYifJvbi"]]http://pastebin.com/nYifJvbi[[/LINK]]

Let me know how it went.


Daniella comments:

It worked! Thank you so much.

2011-08-10

Jerson Baguio answers:

can you share the code on this single-btf-tour-operators.php


Daniella comments:

Why is that necessary?