Я пытаюсь добавить заголовок изображения к атрибуту alt
изображений в галерее, но мой код не работает.Ниже приведен фрагмент шорткода галереи, модифицированный для реализации слайд-шоу.Внизу я использую wp_get_attachment_image()
с $default_attr
в качестве массива атрибутов, содержащих заголовок.Заголовок не отображается в HTML.
$id = intval($id);
if ( 'RAND' == $order )
$orderby = 'none';
if ( !empty($include) ) {
$include = preg_replace( '/[^0-9,]+/', '', $include );
$_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
$attachments = array();
foreach ( $_attachments as $key => $val ) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif ( !empty($exclude) ) {
$exclude = preg_replace( '/[^0-9,]+/', '', $exclude );
$attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
} else {
$attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
}
if ( empty($attachments) )
return '';
if ( is_feed() ) {
$output = "\n";
foreach ( $attachments as $att_id => $attachment )
$output .= wp_get_attachment_link($att_id, $size, true) . "\n";
return $output;
}
$i = 0;
$default_attr = array(
'src' => $src,
'class' => "attachment-$size",
'alt' => trim(strip_tags( $attachment->post_excerpt ))
);
foreach ( $attachments as $attachment ) {
<a href='".wp_get_attachment_url($attachment->ID)."'>".wp_get_attachment_image($attachment->ID, $size, false, $default_attr)."</a>
}
return $output;