• 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:

    https://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

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter LockeAG4

    (@lockeag4)

    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! ??

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

    see: https://codex.www.ads-software.com/Gallery_Shortcode

    Thread Starter LockeAG4

    (@lockeag4)

    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

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

    Thread Starter LockeAG4

    (@lockeag4)

    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!…

    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 ??

    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);

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to display all the attached images of the posts’ is closed to new replies.