0

Thanks to Rafael Marques, I have a list of Products and Categories organized based on different created categories. I also have 5 different Custom Page Templates. Now I would like to display the product images (only images, because this is just an image gallery) in each of the pages. The page template looks like:

<?php 
/**
Template Name: Gallery Art
*/
get_header(); ?>
<div id="scrool" class="clearfix">
    <div class="gal item">
        <a class="group4" href="img/gallery/Beauty/Beauty 1.jpg">
            <img src="img/gallery/Beauty/gal/Beauty 1.jpg" alt="Ghazal Photo" width="231" height="149" />
        </a>
    </div>
</div>
<?php get_footer(); ?>

How can I do this based on categories? For example, let's say I have a page called Art and powered based on Art_Page template. How can I add all images (products) to only this template, which is categorized under artCat?

3
  • How do you add the images to a page? Image gallery or featured images?
    – user17408
    Commented Jan 27, 2013 at 21:34
  • I think it is better to be Image Gallery.Can you please let me know what is the different between them?
    – Suffii
    Commented Jan 27, 2013 at 21:52
  • Let's focus on your main question please. Different questions you can open separated.
    – user17408
    Commented Jan 27, 2013 at 22:12

1 Answer 1

1

In your functions.php

function show_all_thumbs() {
    global $post;
    $post = get_post($post);
    $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;
}

In your page template file:

$loop = new WP_Query(
    array(
        'post_type'         => 'demo', // or whatever is called your custom post type
        'cat'               => 5, // or whatever is the "id" for your custom post type category
        'posts_per_page'    => 10
    )
);
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) : $loop->the_post(); 
    echo show_all_thumbs();
endwhile;
endif;

Let us know please.

For different/extra questions which have nothing to do with this topic, please ask them separated, starting a new questions thread.

Example for Featured Image version:

$loop = new WP_Query(
    array(
        'post_type'         => 'demo', // or whatever is called your custom post type
        'cat'               => 5, // or whatever is the "id" for your custom post type category
        'posts_per_page'    => 10
    )
);
if ( $loop->have_posts() ) :
while ( $loop->have_posts() ) : $loop->the_post(); 
    if ( has_post_thumbnail() ) {
    the_post_thumbnail();
} 
endwhile;
endif;
4
  • Hi GRÁVUJ, Thanks for your help but I am not getting any images when I load the page.Can we do this through Feature Image?
    – Suffii
    Commented Jan 29, 2013 at 15:00
  • yes, updated answer with another example code
    – user17408
    Commented Jan 29, 2013 at 18:16
  • Sorry man! but this is still not working! I followed every thing but I do not know why is not working JUST empty page! btway thanks for your help and comments!
    – Suffii
    Commented Jan 29, 2013 at 23:54
  • have you checked the parameters? are they correct. in the above examples they have only example purpose. i can't know what do you have in your dev environment.
    – user17408
    Commented Jan 30, 2013 at 9:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.