Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Trying to fix my custom gallery after the 3.5 upgrade, and using the code below I'm trying to get the first image of the gallery in "large" size above the content output followed by the remaining images in the corresponding gallery in "thumbnail" size...but 'numberposts' => 1 isn't liking what I'm doing for some reason.

And, what's the trick to completely stripping the gallery shortcode [and it's contents] out?

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);
}}?>
share|improve this question

2 Answers 2

What do you mean by "isn't liking what I'm doing for some reason."? What happens? Does it break or just not return the amount you expected? Is the second query working?

As for the trick of stripping shortcodes it's just as easy as:

<?php echo strip_shortcodes( get_the_content() ); ?>
share|improve this answer

Yeah I shouldve been clear...the top is returning all of the images instead of only the first one (1) whereas the bottom is returning all of the remaining images (-1).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.