我有自定义库短代码的问题,并且缺少每个库块中的第一个图像。例如:[库ID=“1,2,3,4,5”]仅显示2,3,4,5张图片。
这个自定义短代码是wordpress插件的一部分,该插件可以生成自定义提要。它使用相同的插件和主题(在localhost上测试)在我的第二个站点上正常工作。我试图更新整个wordpress安装,禁用了所有插件,但没有成功。那么问题出在db或服务器的某个地方?我不知道如何调试这个奇怪的行为,需要一些建议。
自定义库快捷码:
add_shortcode(\'gallery\', \'gallery_shortcode\');
add_filter( \'post_gallery\', \'yturbo_gallery\', 9999999, 2 );
$content = do_shortcode($content);
$content = yturbo_do_gallery($content);
$ytad4meta = get_post_meta($post->ID, \'ytad4meta\', true);
$ytad5meta = get_post_meta($post->ID, \'ytad5meta\', true);
function yturbo_gallery( $output, $attr ) {
$yturbo_options = get_option(\'yturbo_options\');
if ( ! is_feed($yturbo_options[\'ytrssname\']) ) {return;}
$post = get_post();
static $instance = 0;
$instance++;
if ( ! empty( $attr[\'ids\'] ) ) {
// \'ids\' is explicitly ordered, unless you specify otherwise.
if ( empty( $attr[\'orderby\'] ) ) {
$attr[\'orderby\'] = \'post__in\';
}
$attr[\'include\'] = $attr[\'ids\'];
}
$html5 = current_theme_supports( \'html5\', \'gallery\' );
$atts = shortcode_atts( array(
\'order\' => \'ASC\',
\'orderby\' => \'menu_order ID\',
\'id\' => $post ? $post->ID : 0,
\'itemtag\' => $html5 ? \'figure\' : \'dl\',
\'icontag\' => $html5 ? \'div\' : \'dt\',
\'captiontag\' => $html5 ? \'figcaption\' : \'dd\',
\'columns\' => 3,
\'size\' => \'thumbnail\',
\'include\' => \'\',
\'exclude\' => \'\',
\'link\' => \'\'
), $attr, \'gallery\' );
$id = intval( $atts[\'id\'] );
$atts[\'include\'] = str_replace(array("»","″"), "", $atts[\'include\']);
$atts[\'orderby\'] = str_replace(array("»","″"), "", $atts[\'orderby\']);
$atts[\'order\'] = str_replace(array("»","″"), "", $atts[\'order\']);
$atts[\'exclude\'] = str_replace(array("»","″"), "", $atts[\'exclude\']);
if ( ! empty( $atts[\'include\'] ) ) {
$_attachments = get_posts( array( \'include\' => $atts[\'include\'], \'post_status\' => \'inherit\', \'post_type\' => \'attachment\', \'post_mime_type\' => \'image\', \'order\' => $atts[\'order\'], \'orderby\' => $atts[\'orderby\'],\'offset\' => 0 ) );
$attachments = array();
foreach ( $_attachments as $key => $val ) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif ( ! empty( $atts[\'exclude\'] ) ) {
$attachments = get_children( array( \'post_parent\' => $id, \'exclude\' => $atts[\'exclude\'], \'post_status\' => \'inherit\', \'post_type\' => \'attachment\', \'post_mime_type\' => \'image\', \'order\' => $atts[\'order\'], \'orderby\' => $atts[\'orderby\'],\'offset\' => 0 ) );
} else {
$attachments = get_children( array( \'post_parent\' => $id, \'post_status\' => \'inherit\', \'post_type\' => \'attachment\', \'post_mime_type\' => \'image\', \'order\' => $atts[\'order\'], \'orderby\' => $atts[\'orderby\'],\'offset\' => 0 ) );
}
if ( empty( $attachments ) ) {
return \'\';
}
$output = PHP_EOL.\'<div data-block="gallery">\'.PHP_EOL;
foreach ( $attachments as $id => $attachment ) {
$output .= \'<img src="\'.wp_get_attachment_url($id) . \'"/>\'.PHP_EOL;
}
$output .= \'</div>\'.PHP_EOL;
return $output;
}
我曾尝试按照这里为gallery shortcode建议的那样编辑插件代码,但在这种情况下,两个安装都会显示除第一个以外的所有图像。
function yturbo_gallery( $output, $attr ) {
$yturbo_options = get_option(\'yturbo_options\');
if ( ! is_feed($yturbo_options[\'ytrssname\']) ) {return;}
$output = "<div data-block=\\"gallery\\">";
$posts = get_posts(array(\'include\' => $attr[\'ids\'],\'post_type\' => \'attachment\'));
foreach($posts as $imagePost){
$output .= "<img src=\'".wp_get_attachment_image_src($imagePost->ID, \'full\')[0]."\'>";
}
$output .= "</div>";
return $output;
}
我已经用
\'offset\' => 0
没有结果。