• Hi there,

    I have the following code that displays content/listings from a category called “shops-and-business”. I also have another category called “events” that I would like to display.

    I am wondering how I can do this in this file? I’m guessing I can do an if statement? So if category =”shops-and-business” then show those. If category = “events” then show events.

    Any ideas if this is possible with this code?

    <!-- LATEST BUSINESS LISTINGS GRID ITEM -->
    <div class="col-md-12 latest-business-item-container latest-event-item-container">
      <div class="latest-business-item">
        <div class="featured-listing-badge">
          <?php require locate_template( 'templates/single-listing/previews/partials/head-buttons.php' ) ?>
        </div>
        <div class="listing-image">
          <?php if ($options['background']['type'] == 'gallery' && ( $gallery = $listing->get_field( 'gallery' ) ) ): ?>
          <div class="owl-carousel lf-background-carousel">
            <?php foreach ( array_slice( $gallery, 0, $gallery_count ) as $gallery_image ): ?>
            <div class="item"> <img src="<?php echo esc_url( c27()->get_resized_image( $gallery_image, $bg_size ) ) ?>" />
              <div class="lf-background" style="background-image: url('<?php echo esc_url( c27()->get_resized_image( $gallery_image, $bg_size ) ) ?>');"></div>
            </div>
            <?php endforeach ?>
          </div>
          <?php else: $options['background']['type'] = 'image'; endif; // Fallback to cover image if no gallery images are present ?>
          <?php if ($options['background']['type'] == 'image' && ( $cover = $listing->get_cover_image( $bg_size ) ) ): ?>
          <div class="lf-background" style="background-image: url('<?php echo esc_url( $cover ) ?>');"></div>
          <?php endif ?>
        </div>
        <div class="p-30">
          <div class="logo-bookmark">
            <?php if ( $logo = $listing->get_logo() ): ?>
            <div class="listing-avatar" style="background-image: url('<?php echo esc_url( $logo ) ?>')"></div>
            <?php endif ?>
            <?php
            $postId = $listing->get_id();
            $bookmarked = \MyListing\ Src\ Bookmarks::exists( ( int )$postId, get_current_user_id() );
            if ( $bookmarked ) {
              $classes = 'nobookmarked bookmarked';
              $bmText = "Remove Bookmark";
              $fontClass = "fa fa-regular fa-heart";
            } else {
              $classes = 'nobookmarked';
              $bmText = "Add Bookmark";
            }
            if ( $is_caching ) {
              $classes = '<var #saved></var>';
            }
    
            ?>
            <div class="tt-item"> <span class="tt-top-white-border-top-purple b-0"><?php echo $bmText ?></span> <a  id="latest_<?php echo $postId ?>" aria-label="Bookmark button" href="#" class="listing-bookmark-btn c27-bookmark-button <?php echo $classes?>" data-listing-id="<?php echo $postId; ?>" onclick="MyListing.Handlers.Bookmark_Button(event, this)"> </a> </div>
          </div>
          <div class="mt-30"> <a href="<?php echo esc_url( $listing->get_link() ) ?>">
            <h4 class="case27-primary-text listing-preview-title"> <?php echo $listing->get_name() ?>
              <?php if ( $listing->is_verified() ): ?>
              <i class="tt-item icons8-verified-badge-2 brand-purple"><span class="tt-top-white-border-top-purple b-0">This is a verified listing</span></i>
              <?php endif ?>
            </h4>
            </a> </div>
          <div class="listing-category-open">
            <div class="category-yellow-purple mt-10"><?php echo do_shortcode('[categories id="'.$postId .'"]'); ?></div>
            <div>
              <?php
              if ( !empty( $options[ 'buttons' ] ) ) {
                foreach ( ( array )$options[ 'buttons' ] as $button ) {
                  $string = $button[ 'label' ];
                  $attributes = [];
                  $classes = [ 'lf-head-btn', has_shortcode( $button[ 'label' ], '27-format' ) ? 'formatted' : '' ];
    
                  if ( $is_caching ) {
                    list( $string, $attributes, $cls ) = \MyListing\ prepare_string_for_cache( $string, $listing );
                    $classes += $cls;
                  } elseif ( \MyListing\ str_contains( $string, '[[work_hours]]' ) ) {
                    $classes[] = 'open-status listing-status-' . $listing->schedule->get_status();
                  }
    
                  if ( \MyListing\ str_contains( $string, '[[:reviews-stars]]' ) ) {
                    $classes[] = 'listing-rating rating-preview-card';
                  }
    
                  $content = do_shortcode( $listing->compile_string( $string ) );
                  if ( !empty( $content ) ) {
                    ?>
              <div class="<?php echo esc_attr( join( ' ', $classes ) ) ?>" <?php echo join( 'dff ', $attributes ) ?>>
                <div class="opening-time-tag">
                  <div class="status"><?php echo $content;?></div>
                </div>
              </div>
              <?php
              }
              }
              }
              ?>
            </div>
          </div>
          <div class="listing-description">
            <?php require locate_template( 'templates/single-listing/previews/partials/info-fields.php' ) ?>
          </div>
          <a  href="<?php echo get_permalink($postId) ?>" class="btn-brand-green-purple-solid-outline btn-view-listing">View Business</a> </div>
      </div>
    </div>
    <!-- end LATEST BUSINESS LISTINGS GRID ITEM -->
Viewing 1 replies (of 1 total)
  • Mayuri

    (@mayuripatel)

    Hello,

    using IF ELSE , you can do 2 different codes , and also manage classes which are relevant to category .

Viewing 1 replies (of 1 total)
  • The topic ‘Displaying content from different categories? (if else maybe?)’ is closed to new replies.