Treehouse: Grow your CSS skills. Land your dream job.

Custom WordPress Loop Question…

  • # December 21, 2011 at 7:24 pm

    Ok… I’ve got a slider plugin that creates a custom post type and each image is a post in that post type. It has a shortcode generator that is used to help a user copy/paste the shortcode into the page where they want to feature it. I love this little gallery, easily customizable and easy to use… except the shortcode generator part. So what I’d like to do since I’m doing this on the home page only anyway is be able to grab the ids of the posts and create the shortcode bit by hand.

    The shortcode is formatted like this:
    [galaxy_slider slide=”60,59,58″ animation=”fade”]

    So I’m trying to figure out how to loop through all posts in the GalaxySlide post type and grab their id’s and then put them together in the slide=”60,59,58′ part.

    Can anyone point me in the right direction…?

    # December 21, 2011 at 7:41 pm

    Ok… answered my own question… lol… I love how sometimes, writing out the problem in a forum post triggers the answer in my brain. For anyone else that wants to figure out how to do this:

                    < ?php
    $args = array( 'post_type' => 'galaxy_slider' );
    $loop = new WP_Query( $args );
    $shortcode = '[galaxy_slider slide="';
    while ( $loop->have_posts() ) : $loop->the_post();
    $slideIDs = $slideIDs . $post->ID . ',';
    $slideIDs = substr($slideIDs, 0, -1);
    $shortcode = $shortcode . $slideIDs . '" animation="horizontal-push" speed="600" width="650" height="350"]';

    < ?php echo do_shortcode($shortcode); ?>

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.