Так что мой код частично работает. Я могу позвонить по правильному идентификатору категории и вытащить правильное изображение, НО, когда я go перехожу на следующую страницу в нумерации страниц, изображения категории не отображаются, пока я не нажму refre sh. Я не думаю, что правильно делаю свои вложенные операторы else, я пробовал разные комбинации безрезультатно. Я пытаюсь назначить избранные изображения в зависимости от категории события, если для этого события не установлено выбранное изображение. Вот мой код. Любая помощь будет оценена.
// Featured Image for Certain Event Categories
function my_default_featured_images() {
global $post;
$featured_image_exists = has_post_thumbnail($post->ID);
if (!$featured_image_exists) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment);
}
}
// Identify the category this should apply to.
else if ( tribe_is_event( $post->ID ) ) {
if ( tribe_event_in_category( 'charity-fundraising' ) ) {
set_post_thumbnail( $post->ID, '32766' ); // Change '0000' to the ID of whatever image you want as a default
} else if ( tribe_is_event( $post->ID ) ) {
} if ( tribe_event_in_category( 'trunk-shows' ) ) {
set_post_thumbnail( $post->ID, '32768' ); // Change '0000' to the ID of whatever image you want as a default
} else if ( tribe_is_event( $post->ID ) ) {
} if ( tribe_event_in_category( 'performing-arts' ) ) {
set_post_thumbnail( $post->ID, '32828' ); // Change '0000' to the ID of whatever image you want as a default
wp_reset_postdata();}
}}}
add_action('the_post', 'my_default_featured_images');
Это мой обновленный код, который теперь получает синтаксические ошибки перед вторым, третьим оператором if. Я все еще изучаю синтаксис propper, поэтому я не уверен, как это исправить.
// Featured Image for Certain Event Categories
function my_default_featured_images() {
global $post;
$featured_image_exists = has_post_thumbnail($post->ID);
if (!$featured_image_exists) {
$attached_image = get_children( "post_parent=$post->ID&post_type=attachment&post_mime_type=image&numberposts=1" );
if ($attached_image) {
foreach ($attached_image as $attachment_id => $attachment) {
set_post_thumbnail($post->ID, $attachment);
wp_reset_postdata;
}
}
// Identify the category this should apply to.
else if ( tribe_is_event( $post->ID ) )
if ( tribe_event_in_category( 'charity-fundraising' ) )
set_post_thumbnail( $post->ID, '32766' ); // Change '0000' to the ID of whatever image you want as a default
} else if ( tribe_is_event( $post->ID ) )
if ( tribe_event_in_category( 'trunk-shows' ) )
set_post_thumbnail( $post->ID, '32768' ); // Change '0000' to the ID of whatever image you want as a default
else if ( tribe_is_event( $post->ID ) )
if ( tribe_event_in_category( 'performing-arts' ) )
set_post_thumbnail( $post->ID, '32828' ); // Change '0000' to the ID of whatever image you want as a default
}
add_action('the_post', 'my_default_featured_images');