<?php
/*
Template Name:My Product List Page
*/

?>   

<?php get_header(); ?>
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post-body pages">        
<?php get_sidebar('left'); ?> 
<div class="posts-wrap three_col"> 
   <? //print_r($post)?>
<div class="post" id="page">
        
        <h2 class="page-title">
            
            <?php the_title(); ?>
        </h2>

            <div class="entry-content" id="page-content">
            
                <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>

                <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
            </div><!-- end #page-content -->

    </div><!-- end #page -->
    <div class="cat_static_blocks_product">  
           <?php  
           $category_id = get_post_meta($post->ID, 'category_id', true); 
           $args = array(
                        'type'                     => 'post',
                        'child_of'                 => $category_id,
                        'parent'                   => '',
                        'orderby'                  => 'slug',
                        'order'                    => 'ASC',
                        'hide_empty'               => 1,
                        'hierarchical'             => 1,
                        'exclude'                  => '',
                        'include'                  => '',
                        'number'                   => '',
                        'taxonomy'                 => 'category',
                        'pad_counts'               => false );
           $cats = get_categories($args); 
             // print('<pre>');
             //  print_r($cats); 
               
           if($cats) {?>
               <div class="gef"><strong> Guide entry for: </strong>
                    <?php foreach ($cats as $cat_child):?>
                         <a href="#cat_<?php echo $cat_child->cat_ID; ?>"><?php echo $cat_child->cat_name; ?> </a>
                    <?php endforeach; ?>
               </div>
               <div class="cat_detail_main"> 
               <?php foreach ($cats as $cat_child):?>
               
                        <?php $cat_id_page = $cat_child->cat_ID; ?>
                        <h4 id = "cat_<?php echo $cat_child->cat_ID; ?>"><?php echo get_cat_name($cat_id_page);  ?></h4>
                        <?php $args = array( 'numberposts' => '-1','cat'=>"$cat_id_page",'order'=>'asc','orderby'=>'title' );
                      $pageposts = get_posts( $args );
                      $i_row = 1;?>
                      <?php foreach ($pageposts as $post): ?> 
                        
                        <div class="cat_item  <?php //if($i_row==1){echo 'first';}?>">
                              <table>
                                <tr>
                                    <td width="70" valign="top" bgcolor="#ffffff" align="center" style="padding: 5px"> 
                                     <?php $p_src =  get_Image_url($post->ID,'m','thumbnail'); ?>
				     <?php $url_product = get_post_meta($post->ID, 'url_product', true); ?> 
                                     <a href="<?php echo $url_product; ?>" target="_blank">
                                     <img src="<? echo $p_src?>" alt="" width="60" border="0">
                                     </a>
                                    </td>
                                    <td valign="top"  style="padding: 5px"><?php echo apply_filters('the_content', $post->post_content); ?></td>
                                </tr>
                              </table>
                        </div>
                        <?php //if($i_row==2){echo '<br class="clear"> '; $i_row=0;}?>
                        <?php $i_row += 1; ?>
                        <?php endforeach; ?>
                        <br class="clear"><br>
               <?php endforeach; ?>
              </div> 
           <?php
           } else {  ?>
                    <div class="cat_static_blocks_product_s" style="margin-top: -5px;">
                     <?php $cat_id_page = $category_id; ?> 
                    <?php $args = array( 'numberposts' => '-1','cat'=>"$cat_id_page",'order'=>'asc','orderby'=>'ID' );
                      $pageposts = get_posts( $args );
                      $i_row = 1;?>
                      <?php foreach ($pageposts as $post): ?> 
                        
                        <div class="cat_item ">
                              <table>
                                <tr>
                                    <td width="70" valign="top" bgcolor="#ffffff" align="center" style="padding: 5px"> 
					<?php $url_product = get_post_meta($post->ID, 'url_product', true); ?> 
                                     	<a href="<?php echo $url_product; ?>" target="_blank"> 
					<img src="<? echo get_Image_url($post->ID,'m','thumbnail');?>" alt="" width="60">
					</a>
				    </td>
                                    <td valign="top"  style="padding: 5px"><?php echo apply_filters('the_content', $post->post_content); ?></td>
                                </tr>
                              </table>
                        </div>
                        <?php //if($i_row==2){echo '<br class="clear"> '; $i_row=0;}?>
                        <?php $i_row += 1; ?>
                        <?php endforeach; ?>
                        <br class="clear"> 
                  </div>
           <?php    
           }?>
      </div>                 
    
            <?php endwhile; endif; ?>
            
    <?php edit_post_link( __('Edit this page', 'blank'), '<p>', '</p>'); ?>
 </div><!-- end .posts-wrap -->
    
<?php get_sidebar('right'); ?>
</div>
<?php get_footer('all'); ?>