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

Gregory Lancaster greglancaster71 at gmail.com
Wed Aug 14 20:29:44 UTC 2013


My current code is this:

<?php global $post;
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag);{
$tag_name = $tag->name;}
$end =  $tag_name;
?>

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


      <aside class="sidebar <?php echo roots_sidebar_class(); ?>"
role="complementary">
      <?php if (roots_display_sidebar()) : ?>
        <?php include roots_sidebar_path(); ?>
      <?php endif; ?>
      </aside><!-- /.sidebar -->


So it looks for left-sidebar-(tagname) first and if that php file doesnt
exist, it reverts to the default left-sidebar.php.   How would I change
this to instead load left-sidebar-tag.php and within that file search for
the correct tag to show, and if it does not exist show the default
left-sidebar.php?

I can easily have it call the left-sidebar-tag.php but once its called I
dont know what to put inside that file to determine what should be loaded.
 Maybe something like

<?php global $post;
$tags = wp_get_post_tags($post->ID);
foreach ($tags as $tag);{
$tag_name = $tag->name;}
$end =  $tag_name;
?>

if $end == ($posd->ID);
include  //no idea what it would include, since it would be including a
specific portion of the file only...


On Tue, Aug 13, 2013 at 12:09 PM, J.D. Grimes <jdg at codesymphony.co> wrote:

> > Thank you, I can hardly believe how helpful people are here.
>
> You're welcome!
>
> >  The code I pasted above earlier is for a left-sidebar used for gallery
> images and bootstrap scrollspy to show
> > people where they are on specific pages.  Thats why I need it to call
> based
> > on the post tag- so it shows along with the appropriate content.
>
> Sorry, I'm not sure what code you mean. Maybe you could post a link to a
> Gist (https://gist.github.com/)
>
> > Knowing all that, is it still possible to call the sidebar from one file
> with conditionals?
>
> Definitely.
> _______________________________________________
> 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