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

Different menus for posts that use the same template WordPress

  • SOLVED

EDIT:
I am not sure if I put my question across clearly. Here I am trying again.

These two pages:
http://uglyd.com/uglydwordpress/darrentieste/
http://uglyd.com/uglydwordpress/davidbyun/
Use gallery.php template to display.
Note "Website" - I need to have unique links appearing in this same layout for 8 posts. I.e. DarrenTieste has his own links, David Byun has his own, photographer 3 has his own....

But I am using a .php template which is the same for all these posts. Is there a way to allow unique links just using one gallery.php template for all 8 posts?

<strong>I can array my menus and stuff, but how do I call for menuA for postA and menuB for postB if both postA & postB use the same template? </strong>

<em>original question posted (ignore, just for reference)
I have a photography agency website and I need to create pages for 8 different photographers. I use a template (gallery.php) to display their gallery. However, on each of the posts under their name, I need to have unique links.
e.g.
Photographer A : links to photographer A's website & PDF portfolios
Photographer B: links to photographer B's website & PDF portfolios

However, since each page uses the gallery.php template, it seems impossible to achieve this. I am posting this in the hope that someone knows a way to solve this. Otherwise I will have to duplicate the gallery.php scripts and create photographerA.php and photographerB.php templates just to put in the unique weblinks.

Notes:
-Each gallery exists on a post, not a page. I am using a plugin that allows for custom templates for posts.
-I am thinking it might be possible to use Wordpress' custom menus. Is it possible to use PHP to call the name of each menu? For instance, using the post title or the permalink as a php call in the code for calling a custom menu?
</em>

Answers (5)

2011-12-14

Francisco Javier Carazo Gil answers:

Hi ditzydeezy,

You have to create the menus in the dashboard and then in the template:

if(condition_menu_a)
wp_nav_menu( array('menu' => 'Menu A' ));
else
wp_nav_menu( array('menu' => 'Menu B' ));


In menu you can use id, slug or name.


Francisco Javier Carazo Gil comments:

To create the condition, you can use:


Permalink for this post:
<?php echo get_permalink(); ?>


With the permalink you can do the conditions:


if(get_permalink() == "photographerA")
wp_nav_menu( array('menu' => 'Menu A' ));
else if(get_permalink() == "photographerB")
wp_nav_menu( array('menu' => 'Menu B' ));


Hope it helps!


Francisco Javier Carazo Gil comments:

<em>I can array my menus and stuff, but how do I call for menuA for postA and menuB for postB if both postA & postB use the same template?
</em>

Yes you can. You have to use my code you know in which post you are using get_permalink and then you can echo the wp_menu_nav you want.


ditzydeezy comments:

Yes! I think this is what I need.

These conditions would go on the gallery.php template site, am I right?


Francisco Javier Carazo Gil comments:

Yes, if get_permalink() is not working (return false) you can always know your URL with:


function get_current_url () {
if (isset($_SERVER['REQUEST_URI'])) {
$current_url = $_SERVER['REQUEST_URI'];
} else {
$current_url = $_SERVER['SCRIPT_NAME'];
$current_url .= (!empty($_SERVER['QUERY_STRING'])) ? '?' . $_SERVER['QUERY_STRING'] : '';
}
return $current_url;
}


With URL you can strip it with: http://php.net/manual/en/function.explode.php and take the last part of array (where you can find the photographer).


ditzydeezy comments:

<blockquote>
if(get_permalink() == "photographerA")

wp_nav_menu( array('menu' => 'Menu A' ));

else if(get_permalink() == "photographerB")

wp_nav_menu( array('menu' => 'Menu B' ));</blockquote>

Can these lines be repeated for more than one "if"? I have 8 photographers to write this for lol.

Btw I will increase the prize by $5, this has been helpful!


ditzydeezy comments:

Got it to work already. I don't think I actually needed to use the

<?php echo get_permalink ?>

2011-12-14

John Cotton answers:

I think the answer to this question:

http://wpquestions.com/question/showLoggedIn/id/3396

will work for you..


John Cotton comments:

I should have added that I meant "my answer" :)

The accepted answer might help too.


John Cotton comments:

Hmm.. with 8 posts, I WOULD go the custom field route.

Add one or more custom fields called _photographer_link on each post and then get back the array get_postmeta( $post->ID, '_photographer_link ', false), loop through that array and output.


ditzydeezy comments:

Sorry I am pretty lost with your answer, I believe Francisco offered me what I needed! Thank you.

2011-12-14

Arnav Joy answers:

you are saying that each of your post is a photographer information , if it is true then you can use custom fields at each of your post to give link to the site .

2011-12-14

Sébastien | French WordpressDesigner answers:

the response of francisco is well
no ?


Sébastien | French WordpressDesigner comments:

another solution :

each artist have a page
each link can be the value of a custom field

in each "artist page" you can create several custom fields i.e. : a custom field "his site"
and you display a link in the public page. The target of this link is the value of the custom field "his site"


ditzydeezy comments:

I think I know what you are saying, but that is what I am trying to avoid here! It will require duplicate templates which is a waste.


Sébastien | French WordpressDesigner comments:

@julio : les grands esprits se rencontrent !

@ditzydeezy : As you can see, simplicity is a french quality : Julio have the same idea :-)
It's probably because it is well a good idea :-)

2011-12-14

Julio Potier answers:

I got a better idea :
You use post meta data (get_post_meta) and create a "fake" menu with these values.
Example :
Photographer A
post 1
meta data "url" : http://www.photoa.com
meta data "pdf" : AA.pdf
etc

Photographer A
post 2
meta data "url" : http://www.photob.net
meta data "pdf" : b_b.pdf
etc

Then in <em>your </em>gallery.php template, your create your menu witlh some UL/LI tags and get values from posts

- No conditions needed
- No new menus for each member
- Easy to maintain

See you (on skype ? ;p)


ditzydeezy comments:

Thanks but I need this to work with the wordpress appearance menus for future ease of use!