WordPress.org

Forums

[resolved] Can you bypass Template Hierarchy? (5 posts)

  1. klint01
    Member
    Posted 4 years ago #

    I want to be able to provide two options for the user when viewing archive postings. One view would be more gallery style (multiple smaller posts on one page in columns and rows). The other view would be the standard stacked posts (one column).

    I have setup tag.php file to show gallery and archive.php to show standard. By default, if the user clicks on a tag in a posting, they will see the tag.php gallery view.

    How can I provide an option to bypass the tag.php and take the user directly to archive.php, if the users chooses to view the page in standard mode?

  2. stvwlf
    Member
    Posted 4 years ago #

    The code I'm posting is not specifically related to what you are asking about. It shows how to call in different single post display templates under different conditions.

    I suggest you adapt this technique to work with your requirements. The principle will be the same, just the application is quite different.

    The entire contents of single.php are replaced with this IF - ELSE logic. The contents of the existing single.php are moved into the subsidiary template files as required.

    <?php $post = $wp_query->post;
      if ( in_category('1') ) {
      include(TEMPLATEPATH . '/single1.php');
      } elseif ( in_category('2') ) {
      include(TEMPLATEPATH . '/single2.php');
      } else {
      include(TEMPLATEPATH . '/single_other.php');
      } ?>

    Hopefully this will help you

  3. klint01
    Member
    Posted 4 years ago #

    Thanks for the information. I will have to look into this approach.

  4. klint01
    Member
    Posted 4 years ago #

    This concept worked perfectly. I had to learn how to pass a specific variable and check it but in the end it came out great.

    Thanks!

    This topic can be closed.

  5. stvwlf
    Member
    Posted 4 years ago #

    glad to hear it.

    There is a place where you as the originator can mark this topic as resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic