WordPress

Wtyczka WP: kalendarz wydarzeń pokazuje organizatorom wyróżniony obraz, jeśli wyróżniony obraz wydarzeń jest pusty

  • 19 kwietnia, 2023
  • 3 min read
Wtyczka WP: kalendarz wydarzeń pokazuje organizatorom wyróżniony obraz, jeśli wyróżniony obraz wydarzeń jest pusty


W widoku listy iw widoku pojedynczego wydarzenia chcę pokazać obraz polecany przez organizatorów, jeśli obraz polecany w wydarzeniach jest pusty. Do tej pory dodałem opisywany obraz.php w motywie potomnym folderu plemię/v2/list/event/featured-image.php iw pliku poprawiłem oryginalny kod:

<?php
/**
 * View: List View - Single Event Featured Image
 *
 * Override this template in your own theme by creating a file at:
 * [your-theme]/tribe/events/v2/list/event/featured-image.php
 *
 * See more documentation about our views templating system.
 *
 * @link 
 *
 * @version 5.0.0
 *
 * @var WP_Post $event The event post object with properties added by the `tribe_get_event` function.
 *
 * @see tribe_get_event() For the format of the event object.
 */

if ( !$event->thumbnail->exists ) {
    return;
}

?>
<div class="tribe-events-calendar-list__event-featured-image-wrapper tribe-common-g-col">
    <a
        href="<?php echo esc_url( $event->permalink ); ?>"
        title="<?php echo esc_attr( $event->title ); ?>"
        rel="bookmark"
        class="tribe-events-calendar-list__event-featured-image-link"
        tabindex="-1"
    >
        <img
            src="<?php echo esc_url( $event->thumbnail->full->url ); ?>"
            <?php if ( ! empty( $event->thumbnail->srcset ) ) : ?>
                
            <?php endif; ?>
            <?php if ( ! empty( $event->thumbnail->alt ) ) : ?>
                alt="<?php echo esc_attr( $event->thumbnail->alt ); ?>"
            <?php else : // We need to ensure we have an empty alt tag for accessibility reasons if the user doesn't set one for the featured image ?>
                alt=""
            <?php endif; ?>
            <?php if ( ! empty( $event->thumbnail->title ) ) : ?>
                title="<?php echo esc_attr( $event->thumbnail->title ); ?>"
            <?php endif; ?>
            class="tribe-events-calendar-list__event-featured-image"
        />
    </a>
</div>

do następujących:

<?php
/**
 * View: List View - Single Event Featured Image
 *
 * Override this template in your own theme by creating a file at:
 * [your-theme]/tribe/events/v2/list/event/featured-image.php
 *
 * See more documentation about our views templating system.
 *
 * @link 
 *
 * @version 5.0.0
 *
 * @var WP_Post $event The event post object with properties added by the `tribe_get_event` function.
 *
 * @see tribe_get_event() For the format of the event object.
 */

 // Get the event organizer's ID
 $organizer_id = tribe_get_organizer_id();

 // Check if the organizer has a featured image
 if ( has_post_thumbnail( $organizer_id ) ) {
     // If the organizer has a featured image, display it
     $image_html = get_the_post_thumbnail( $organizer_id, 'medium' );
 } else {
     // If the organizer doesn't have a featured image, display the event's featured image
     $image_html = get_the_post_thumbnail( null, 'medium' );
 }

?>
<div class="tribe-events-calendar-list__event-featured-image-wrapper tribe-common-g-col">
    <a
        href="<?php echo esc_url( $event->permalink ); ?>"
        title="<?php echo esc_attr( $event->title ); ?>"
        rel="bookmark"
        class="tribe-events-calendar-list__event-featured-image-link"
        tabindex="-1"
    >
        <img
            src="<?php echo ( $image_html ); ?>"

            <?php else : // We need to ensure we have an empty alt tag for accessibility reasons if the user doesn't set one for the featured image ?>
                alt=""
            <?php endif; ?>
            <?php if ( ! empty( $event->thumbnail->title ) ) : ?>
                title="<?php echo esc_attr( $event->thumbnail->title ); ?>"
            <?php endif; ?>
            class="tribe-events-calendar-list__event-featured-image"
        />
    </a>
</div>

Jak dotąd nie nastąpiły żadne zmiany, a opis wydarzenia jest wyświetlany, jeśli jest obecny. Ale jeśli nie jest obecny, wyróżniony przez organizatorów obraz nie jest wyświetlany.

Warto przeczytać!  Jak dodać logowanie bez hasła w WordPress za pomocą magicznych linków

Korzystam z kalendarza wydarzeń w wersji 6.0.12


Źródło