WordPress.org

Ready to get started?Download WordPress

Forums

Using custom field to get a template. (2 posts)

  1. enderpal444
    Member
    Posted 2 years ago #

    Ok so I have a custom field labled artist_name. Thats calls a name. On the posts for that artist I want to use that custom field to call a different template part that I created for each artist. So I have a file called "name".php in a folder called "artists". So when a post for that artist comes up I can call the corresponding template piece for the sidebar. I can't get it to work though because I don't get how to structure the path. Here's my snipper of code.

    <?php
    global $wp_query;
    $postid = $wp_query->post->ID;
    $artist = get_post_meta($postid, 'artist_name', true); ?>
    <?php locate_template( array( 'artists/' . 'echo $artist_name . '.php' ), true ) ?>
    <?php wp_reset_query(); ?>
  2. esmi
    Forum Moderator
    Posted 2 years ago #

    Place the files in the main theme folder and use get_template_part.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.