Get images

I would like to build a gallery using jquery from scratch in the code, rather than a plugin, that pulls images from the media library. This way my clients can just drop in their images and they will appear. But I dont know the php for this that says generate image in this spot. Also how do I let wordpress know that this is an image for the gallery rather than just an image for another spot?

  • xaviemirmon
    • Site Builder, Child of Zeus

    Hi @keldri20,

    You’ve asked a great question. I took on this challenge for the first time a few months ago when I added a jquery slide show to one of my themes. I had to research up on wordpress loops, functions and jquery slideshows. For you I would add custom content types or pulling from categories to the research list. It’s a very rewarding project when it’s finished because you can see the results when you’re finished. I would have a custom content type or category where the user go to upload the image from there you have the plugin loop through the images the user has uploaded and then render it to the page with your jquery snazziness. If you have anymore specific questions along way let me know and I’ll help to the best of my abilities. Hope that helps!

    Xavier

  • 3SixtyEvolve
    • New Recruit

    Hi @keldri20

    I personally haven’t started a project like this from scratch, but it’s great that Xavier is here to provide some guidance on it. He is very helpful here on the Community, so if you have any questions regarding this setup, please ask away and either him or I would help where we can.

    Have a good day and all the best with your project.

    Gina

  • 3SixtyEvolve
    • New Recruit

    Hi @xaviemirmon

    Since I haven’t done this type of project myself before, would you mind sharing some pointers here for @keldri20 and any other members that might need guidance? It’s always useful when you get input from someone who’s already tried it and worked through the different stages.

    As always, we greatly appreciate your posts to members!

    Have a good day!

    Gina

  • keldri20
    • Flash Drive

    http://codex.wordpress.org/Post_Types

    If I understand this correctly, I would register a custom post type for my carousel images , or if I am trying to bring certain copy content to a specific spot on a page, I would register a custom post type for this as well.

    Then I would run a loop like this?

    <?php query_posts(‘cat=5’:wink:; ?>

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php the_content(); ?>

    <?php endwhile; endif; ?>

    How would I determine what category it is or post it is i.e.(‘cat=5’:wink: or is there another loop to pull this content.

    Thanks for your help, I feel like I am very close to understanding this, hopefully!

    Kate

  • keldri20
    • Flash Drive

    So just for updates, as I believe I have it for custom posts!

    1)

    Here is how I registered my custom post in functions.php (tt_snapshot is the name of custom post)

    add_action( ‘init’, ‘create_post_type’ );

    function create_post_type() {

    register_post_type( ‘tt_snapshot’,

    array(

    ‘labels’ => array(

    ‘name’ => __( ‘Snapshots’ ),

    ‘singular_name’ => __( ‘Snapshot’ )

    ),

    ‘public’ => true,

    ‘has_archive’ => true,

    )

    );

    }

    2) I then queried the post and said one post per page and said while have posts create an <h2> show title,create content div and echo out the content.

    <?php $loop = new WP_Query( array( ‘post_type’ =>’tt_snapshot’, ‘posts_per_page’ => 1 ) ); ?>

    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

    <?php the_title( ‘<h2 class=”entry-title”>‘, ‘</h2>’ ); ?>

    <div class=”entry-content”>

    <?php the_content(); ?>

    </div>

    <?php endwhile; ?>


    Ill let you know how it works for images as well.

    Thanks again you all were very helpful!

    best,

    Kate

  • keldri20
    • Flash Drive

    So ive run into one problem. I was able to use custom posts and the loop to pull in an image into the spot I have for the carosel. Is there a way to use “the loop” to loop through any images from this custom post catagory. If not and I need to use jquery do you recommend that I go about it in any certain way?

    Thanks,

    Kate

  • xaviemirmon
    • Site Builder, Child of Zeus

    Hi @keldri20,

    The code I am using is:

    <div id="carousel">

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>
    <div class="carousel-feature">
    <a href="<?php the_permalink() ?>">
    <?php if (has_post_thumbnail( $post->ID ) ): ?>
    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
    <img src="<?php bloginfo('template_url'); ?>/timthumb.php?src=<?php echo $image[0];?>&h=200&w=300&zc=1" class="carousel-image" alt="Image Caption" >
    <?php endif ?>
    </a>
    <div class="carousel-caption">
    <h4><?php the_title(); ?></h4>
    <p>
    <?php the_content(); ?>
    </p>
    </div>
    </div>
    <?php endwhile ?>

    <?php endif ?>

    </div>

    The preceding pulls the image from the featured image if I remember correctly.

    Xavier

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.