0

I've the code as below:

  <div class="row">        
    <?php
        $pages = array(54,55,56,57,58,74,75,76,77,78);     
        $i = 1;
        foreach ($pages as $page) 
        {
            $post_data = get_post( $page );
            //print_r($post_data);
            $title = $post_data->post_title;
            $content = $post_data->post_content;
            $string = substr($content, 0, 0);
            $themeta = get_post_meta($page,true);
            $metalink = $themeta[0];

            if (has_post_thumbnail($page) ):
            $image = wp_get_attachment_image_src( get_post_thumbnail_id($page), 'single-post-thumbnail' );
            endif;
            $image_URI = $image[0];?>
            <div class="product_pack">                  
                <div class="product_cat">
                    <a href="<?php echo get_permalink( $page ); ?> ">
                        <div class="product_img">
                            <img src="<?php echo $image_URI; ?>" alt="<?php echo $title; ?>"/>
                          <!--  <div class="produc_img-hover"><img src="<?php bloginfo('template_directory');?>/images/prd-star.png" alt="prd-star" /></div>    -->                                         
                        </div>
                        <div class="product_ttl"><?php echo $title; ?></div>
                    </a>                                           
                </div>
           </div>       
            <?php               
        }?>
</div> 

This code provides a link back to the pages as mentioned in the array above. However, I don't want a link to the pages with ID 54 and 75.

If I remove the above IDs from the array, it will also not show the thumbnail and the text (title of the page) however, I want that to show as usual but just that I wanna remove links going to those two pages.

Is there any way to do this.

Please help.

closed as off-topic by Michael, bosco, Jacob Peattie, Christine Cooper, fuxia Oct 6 '18 at 20:54

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

1

I have updated your code please try this and let me know if any query

    <div class="row">        
        <?php
            $pages = array(54,55,56,57,58,74,75,76,77,78);     
            $i = 1;
            foreach ($pages as $page) 
            {
                $post_data = get_post( $page );
                //print_r($post_data);
                $title = $post_data->post_title;
                $content = $post_data->post_content;
                $string = substr($content, 0, 0);
                $themeta = get_post_meta($page,true);
                $metalink = $themeta[0];

                if (has_post_thumbnail($page) ):
                $image = wp_get_attachment_image_src( get_post_thumbnail_id($page), 'single-post-thumbnail' );
                endif;
                $image_URI = $image[0];?>
                <div class="product_pack">                  
                    <div class="product_cat">
<?php if( $page == 54 || $page == 75){}else{ ?>
                        <a href="<?php echo get_permalink( $page ); ?> ">
<?php }?>
                            <div class="product_img">
                                <img src="<?php echo $image_URI; ?>" alt="<?php echo $title; ?>"/>
                              <!--  <div class="produc_img-hover"><img src="<?php bloginfo('template_directory');?>/images/prd-star.png" alt="prd-star" /></div>    -->                                         
                            </div>
                            <div class="product_ttl"><?php echo $title; ?></div>
<?php if( $page == 54 || $page == 75){}else{ ?>
                        </a>                   
<?php }?>                        
                    </div>
               </div>       
                <?php               
            }?>
    </div> 
  • Thanks for your code @Pratik Patel, it worked exactly as desired. – Keyur Amin Sep 27 '18 at 1:23
  • Happy to help you @KeyurAmin :) – Pratik Patel Sep 27 '18 at 5:53

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