WordPress.org

Ready to get started?Download WordPress

Forums

How to display all the attached images of the posts (8 posts)

  1. LockeAG4
    Member
    Posted 4 years ago #

    hey HI , I'm trying to add a Gallery retrieving all the attach images, no matter if they are in the content , but I really don't know what am I doing wrong or if I'm using the incorrect technic .

    For the record... I use:
    WP 2.9.2

    I use the examples that are in this great site:

    http://wpengineer.com/easier-better-solutions-to-get-pictures-on-your-posts/

    and I use this:

    <?php
    $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image') );
    foreach ( $attachments as $attachment_id => $attachment ) {
    	echo wp_get_attachment_image($attachment_id);
    } ?>

    But no image are displayed

    The Only thing I need is too add the <img src="url" /> of the attached images....

    also I was wondering if this could be use as function, I mean:

    function the_gallery() {
    
    $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image') );
    foreach ( $attachments as $attachment_id => $attachment ) {
    	echo wp_get_attachment_image($attachment_id);
    }
    	}

    and Call it with:

    the_gallery();

    Hope somebody could give me a hand on this...

    Thanks in advance

  2. LockeAG4
    Member
    Posted 4 years ago #

    Ok ... I stop trying that :(

    I just put 4 custom fields at the function.php ... to make it work for the moement

    If somebody know how to solve this , It will be very kind! :)

    ...

  3. Safirul Alredha
    Member
    Posted 4 years ago #

    Dude, what's wrong with using shortcode?
    Example:
    [gallery]

    see: http://codex.wordpress.org/Gallery_Shortcode

  4. LockeAG4
    Member
    Posted 4 years ago #

    Hi Zeo ,

    well is beccause I using tabs and jquery to display the content.

    let me share my idea:

    <?php get_header(); ?>
    
    <section id="maincontent">
    
    	<?php the_breadcrumb(); ?>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
      <!-- tabs -->
    <ul class="tabsX">
            <a href="#"><?php the_title(); ?></a>
            <a href="#">Otras Vistas</a>
            <a href="#">Especificaciones</a>
    
    </ul>
    
    	<!-- single pane. it is always visible -->
            <div class="panesX">
    
                    <div class="postX">
                    	<div class="infoX">
                                    <?php the_post_thumbnail(); ?>
                                    <?php the_content(); ?>
    
                            </div>        				
    
                            <br class="clear" />
                    </div>
    
                    <div class="postX">
            		<?php include (TEMPLATEPATH . '/includes/gallery.php'); ?>
         			<br clear="all" />
            	</div>
    
    		<div class="postX">
                        <div class="tableX">
                           <?php spec_id ('spec_id') ?>
                            <?php the_post_thumbnail(); ?>
                        </div>
                            <br class="clear" />
                    </div>
    
            </div>
    
    <?php endwhile; else: ?>
    
    		<p>Sorry, no posts matched your criteria.</p>
    
    <?php endif; ?>
    
    </section>
    
    <?php get_footer(); ?>

    ANd that's why I can't use shortcode

  5. Safirul Alredha
    Member
    Posted 4 years ago #

    How about <?php echo do_shortcode('[gallery]'); ?>?

  6. LockeAG4
    Member
    Posted 4 years ago #

    Zeo Thanks very much for this , unfortunately I'm trying to make that work... but no success .... I place it in a normal loop , without tabs... and is not showing anything...

    step by step

    - I uploaded 4 images to post 7
    - I add <?php echo do_shortcode('[gallery]'); ?> to the loop

    - refresh front post 7

    - the source code and firebug show and empty space inside the class that must contain the gallery.

    and really Thank you!...

  7. sammyb
    Member
    Posted 3 years ago #

    Add this to your theme's functions.php

    function show_all_thumbs() {
        global $post;
        $post = get_post($post);
    
    /* image code */
    $images =& get_children( 'post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent='.$post->post_parent);
    if($images){
    foreach( $images as $imageID => $imagePost ){
    
    unset($the_b_img);
    $the_b_img = wp_get_attachment_image($imageID, 'thumbnail', false);
    $thumblist .= '<a href="'.get_attachment_link($imageID).'">'.$the_b_img.'</a>';
    
    }
    }
    return $thumblist;
    }

    Then in your template file:

    echo show_all_thumbs();

    Hope this helps ;)

  8. sammyb
    Member
    Posted 3 years ago #

    The above code is actually to show the thumbnails on attachment pages... to show them in posts change this:

    $images =& get_children( 'post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent='.$post->post_parent);

    to this:

    $images =& get_children( 'post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent='.$post->ID);

Topic Closed

This topic has been closed to new replies.

About this Topic