数字1在3.5中不合作

时间:2013-02-08 作者:chevy454

尝试在3.5升级后修复我的自定义图库,并使用下面的代码尝试在内容输出上方获取图库的第一个“大”图像,然后在相应的图库中获取“缩略图”大小的剩余图像。。。但是由于某种原因,“numberposts”=>1不喜欢我正在做的事情。

那么,完全剥离gallery短代码(及其内容)的诀窍是什么呢?

single.php

<?php //GETS THE FIRST IMAGE
$args = array(
\'order\'          => \'ASC\',
\'orderby\'        => \'menu_order\',
\'post_type\'      => \'attachment\',
\'post_parent\'    => $post->ID,
\'post_mime_type\' => \'image\',
\'post_status\'    => null,
\'numberposts\'    => 1,
);
$attachments = get_posts($args);
    if ($attachments) {

        foreach ($attachments as $attachment) {

        echo wp_get_attachment_link($attachment->ID, \'thumbnail\', false, false);
}
} else {   
$post_content = $post->post_content;
preg_match(\'/\\[gallery.*ids=.(.*).\\]/\', $post_content, $ids);
$attachment_ids = explode(",", $ids[1]);
foreach ($attachment_ids as $attachment_id) {
        echo wp_get_attachment_link($attachment_id, \'medium\', false, false);
}} ?>

<?php the_content(); ?> 

<?php //GETS REMAINING IMAGES
$args = array(
\'order\'          => \'ASC\',
\'orderby\'        => \'menu_order\',
\'post_type\'      => \'attachment\',
\'post_parent\'    => $post->ID,
\'post_mime_type\' => \'image\',
\'post_status\'    => null,
\'numberposts\'    => -1,
);
$attachments = get_posts($args);
    if ($attachments) {
$no_show=true;
        foreach ($attachments as $attachment) {
if($no_show) {$no_show=false; continue; }
        echo wp_get_attachment_link($attachment->ID, \'thumbnail\', false, false);
}
}  else {   
$post_content = $post->post_content;
preg_match(\'/\\[gallery.*ids=.(.*).\\]/\', $post_content, $ids);
$attachment_ids = explode(",", $ids[1]);
foreach ($attachment_ids as $attachment_id) {
        echo wp_get_attachment_link($attachment_id, \'thumbnail\', false, false);
}}?>

2 个回复
SO网友:tobbr

你说“不喜欢我正在做的事情是出于某种原因”是什么意思?发生了什么?它是否损坏或只是没有返回您预期的金额?第二个查询是否正常?

至于剥离短代码的技巧,它与以下一样简单:

<?php echo strip_shortcodes( get_the_content() ); ?>

SO网友:Chevy454

是的,我应该说清楚。。。顶部返回所有图像,而不是仅返回第一个图像(1),而底部返回所有剩余图像(-1)。

结束

相关推荐

Hierarchical gallery

我想要几个画廊,每个画廊都有几个图片。这种两级结构的正确方式是什么?我会把每个画廊的每一个元素都做成一个帖子。