Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Call get template part if condition is true?

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #40030
    fectio1
    Member

    Defeat by php again.

    I have created a gallery that loops through some custom post types and a category. I am using to call the gallery. However, the title is outside of the loop and I am only calling the gallery if there are any post within a certain category. But my title still shows up due to it being outside of the loop. Calling it inside the loop is obviously not an option. How can I work around this so the title will only show up if the category is true?

    Gallery Title

      my loop
      ?>

    #110877
    chrisburton
    Participant

    @fectio1 post your code on jsfiddle so I can see it properly. Sounds like an if-statement is needed here.

    #110897
    fectio1
    Member

    @ChristopherBurton I tried a few if statements, but was unsuccessful in calling it. My goal is to only get the

    title to show up if the category is true. Hopefully that makes sense.

    #110899
    fectio1
    Member

    I figured it out. I had to use term_exist. Here is an example of my code.

    $term = term_exists(‘your_category_name’, ‘category’);
    if ($term !== 0 && $term !== null) {
    get_template_part(‘gallery’);
    }

    #110902
    chrisburton
    Participant

    @fectio1 What does it output?

    #110903
    chrisburton
    Participant

    @fectio1 Oops. Just noticed you had solved it.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.