[wp-hackers] Help with including custom templates using variables

Nikola Nikolov nikolov.tmw at gmail.com
Mon Aug 12 18:19:54 UTC 2013


>>I do have an issue with both sidebars loading though.  I want it to look
to
>>see if the custom sidebar exists and if not use the default.  heres the
code
>>I came up with...

You can simply use the second argument of get_template_part() like so:

<?php get_template_part('/templates/left-sidebar', $end); ?>

This will first look for the file "/templates/left-sidebar-{$end}.php" and
if it doesn't exist, it will look for the file
"/templates/left-sidebar.php". If that doesn't exist either nothing
happens.

You can read about the function in the codex -
http://codex.wordpress.org/Function_Reference/get_template_part

Nikola


On Mon, Aug 12, 2013 at 8:40 PM, Helen Hou-Sandi <h at hyhs.me> wrote:

> http://codex.wordpress.org/Function_Reference/locate_template
>
> Also take a look at get_queried_object_id() rather than global $post;
> $post->ID and the args for wp_get_post_tags() - you can have it return just
> names and then you should be able to array_pop() it.
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list