• pete polivol

    (@pete-polivol)


    Hello fellow people.

    I am gonna start right away:

    Setup explanation:
    I have 2 portfolio categories (using Avada theme) and I have two different sets of custom fields for each category. I have managed to properly show the correct set of field for the two different categories thus far.

    <?php
    $fields = get_field_objects(); 
    
    if ( $fields ) { ?>
    
    <table class="cf-table" width="auto">
      <thead><th style="float: left;">HEADING 1</th></thead>
        <tbody>
    
          <?php foreach ( $fields as $field_name => $field ) {
             if ($field['type'] == 'true_false') { ?>
                <tr>
                   <td>
                     <?php echo $field['label']; ?></td><td>✓
                   </td>
                </tr>
             <?php }
          } ?>
    
        </tbody>
    </table>
    
    <?php } ?>

    Problem
    What i want to do now is to show a different < thead > based upon the category the post belongs in. I know that this would normally be achieved by using something like:

    `<?php
    $fields = get_field_objects();

    if ( $fields ) { ?>

    <table class=”cf-table” width=”auto”>

    <?php if (is_category(4)) { ?>
    <thead><th style=”float: left;”>HEADING 1</th></thead>
    <?php } else { ?>
    <thead><th style=”float: left;”>HEADING 2</th></thead>
    <tbody>
    <?php } ?>

    <?php foreach ( $fields as $field_name => $field ) {
    if ($field[‘type’] == ‘true_false’) { ?>
    <tr>
    <td>
    <?php echo $field[‘label’]; ?></td><td>✓
    </td>
    </tr>
    <?php }
    } ?>

    </tbody>
    </table>

    <?php } ?>

    Question

    So my questions are:
    1) Since is_category is not used for custom posts like avada portfolio, which is the correct equivalent ?

    2) Is this syntax correct?

    All tips are appreciated! ??

    Thank you

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter pete polivol

    (@pete-polivol)

    Oh man… I think i found it so i am posting this in case someone else needs it.

    <?php
       $fields = get_field_objects();
       global $post;
    
       if ( $fields ) { ?>
          <table class="cf-table" width="auto">
    
            <?php if ( has_term('troxospita', 'portfolio_category')) { ?>
               <thead><th style="float: left;">HEADING 1</th></thead>
            <?php } else { ?>
               <thead><th style="float: left;">HEADING 2</th></thead>
            <?php } ?>
    
            <tbody>
              <?php foreach ( $fields as $field_name => $field ) {
                 if ($field['type'] == 'true_false') { ?>
                    <tr>
                      <td>
                         <?php echo $field['label']; ?>
                      </td>
                      <td>?</td>
                    </tr>
                 <?php }
              } ?>
    
        </tbody>
      </table>
    <?php } ?>
    dianaascher

    (@dianaascher)

    Hi Pete,

    How would you alter this code to display logo1 versus logo2 depending on the page in Avada? Or just to have a different color scheme depending on the type of page?

    Many thanks,
    Diana

    dianaascher

    (@dianaascher)

    Hi Pete,

    How would you alter this code to display logo1 versus logo2 depending on the page in Avada? Or just to have a different color scheme depending on the type of page?

    Many thanks,
    Diana

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘custom fields and custom post type conditional’ is closed to new replies.