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.

I'm using the "flexise" slideshow script to automatically scroll a list of images. The list is hard-coded along with the script in a wordpress template page.

While this works fine, how could you make it so that the slideshow pulled any images added to a special (private) wordpress page instead of having to add each img src manually??

 <ul id="flexiselDemo3">
 <li><img src="http://mysite.com/wp-content/uploads/2014/02/logo.png" /></li>
 <li><img src="http://mysite.com/wp-content/uploads/2014/02/logo2.png" /></li>
 <li><img src="http://mysite.com/wp-content/uploads/2014/02/logo3.png" /></li>
 </ul>  

Many thanks

Trying your suggestion now, I've replaced the above with this:

$attachments = get_posts(array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' =>'any',
// This is where you specify the ID of your private image page
'post_parent' => 6909,
));

if (count($attachments)) {
// We have attachments
?>
<ul id="flexiselDemo3">
    <?php
    // Now we loop through them
    foreach ($attachments as $attachment) {
        ?>
        <li>
            <?php echo wp_get_attachment_image($attachment->ID, 'full'); ?>
        </li>
        <?php
    }
    ?>
</ul>
<?php
} 

But it's throwing an error. Probably something simple, but I'm not experienced enough to debug?

Parse error: syntax error, unexpected '<' in /home4/speedyp/public_html  /speedypancake.com/tmc/wp-content/themes/sirens/page_f.php
share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

Most of this is part of the Codex:

<?php
$attachments = get_posts(array(
    'post_type' => 'attachment',
    'numberposts' => -1,
    'post_status' =>'any',
    // This is where you specify the ID of your private image page
    'post_parent' => $private_page_id,
));

if (count($attachments)) {
    // We have attachments
    ?>
    <ul id="flexiselDemo3">
        <?php
        // Now we loop through them
        foreach ($attachments as $attachment) {
            ?>
            <li>
                <?php echo wp_get_attachment_image($attachment->ID, 'full'); ?>
            </li>
            <?php
        }
        ?>
    </ul>
    <?php
}
?>
share|improve this answer
    
Thank you so much for helping tf. Still very new with wp - I would add that code in the template page? The $private_page_id might be $185 ie. the dollar sign followed by the page id number?? –  speedypancake Feb 4 at 11:55
    
Yes, you would add the above code directly where your hard-coded list is. And no, there is no need for a $ if you specify the value. If your page ID is 185, then it's just 'post_parent' => 185,. –  t f Feb 4 at 11:59
    
Thanks again - I've updated my question using your suggestion and an error code –  speedypancake Feb 4 at 12:12
    
Well, okay, sorry, my bad. You have to wrap the code in between <?php and ?> of course. I updated my answer. –  t f Feb 4 at 12:14
    
tf - You are lucky this is the internet, or I would give you a great big kiss X! Please accept my sincere thanks instead. This is going to help me enormously :) –  speedypancake Feb 4 at 12:17
add comment

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.