$15
echo the number of images attached to a page in the media gallery
Any help is appreciated.
Rich
Rich Staats | 08/11/11 at 11:07am
| Edit
(1) Possible Answers Submitted...
-

Last edited:
08/11/11
11:11amUtkarsh Kukreti says:What code have you used to add the content in the screenshot?
- 08/11/11 11:16am
Rich Staats says:It's using the WPAlchemy Class from farinspace.com, but here is the code to display the metabox:
<?php global $custom_media_access; ?>
<div class="my_meta_control metabox">
<?php
$attachments = (array('post_type' => 'attachment' ));
$count = count($attachments);
?>
<?php $custom_media_access->setGroupName('nn')->setInsertButtonLabel('Insert')->setTab('type'); ?>
<div class="media_mb">
<p><?php echo $custom_media_access->getButton(array('label' => 'Add or Edit Images')); ?> Your Gallery has XX images in the Slide Show</p>
</div>
</div>
Let me know if you need something more.
Rich - 08/11/11 11:17am
Rich Staats says:
<?php
$attachments = (array('post_type' => 'attachment' ));
$count = count($attachments);
?>
was part of my attempt to find a solution myself. - 08/11/11 11:18am
Utkarsh Kukreti says:Try this:
<?php global $custom_media_access, $post; ?>
<div class="my_meta_control metabox">
<?php
$attachments = get_posts(array('post_type' => 'attachment', 'post_parent' => $post->ID ));
$count = count($attachments);
?>
<?php $custom_media_access->setGroupName('nn')->setInsertButtonLabel('Insert')->setTab('type'); ?>
<div class="media_mb">
<p><?php echo $custom_media_access->getButton(array('label' => 'Add or Edit Images')); ?> Your Gallery has <?php echo $count ?> images in the Slide Show</p>
</div>
</div> - 08/11/11 11:22am
Rich Staats says:for some reason, and this where i was having the problem, is that it echos "1" even though currently there are 3 images currently attached to that page
- 08/11/11 11:35am
Utkarsh Kukreti says:Could I get wp-admin access to the site you tried this on, just to confirm?
- 08/11/11 11:38am
Utkarsh Kukreti says:Try this instead for the attachments = line.
$attachments = get_posts(array('post_type' => 'attachment', 'post_parent' => $post->ID, 'post_status' => 'inherit' ));
- 08/11/11 12:33pm
Rich Staats says:ypu that worked. thanks for the quick response.
- 08/11/11 12:35pm
Rich Staats says:how do i award you the money?
- 08/11/11 12:37pm
Utkarsh Kukreti says:http://codewi.se/2011/04/22/voting-assign-prize-money/
- 08/11/11 11:16am
This question has expired.
Rich Staats voted on this question.
Current status of this question: Completed




