我的代码如下:
<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>
这段代码提供了一个指向上面数组中提到的页面的链接。然而,我不想链接到ID为54和75的页面。
如果我从数组中删除上述ID,它也不会显示缩略图和文本(页面标题),但是,我希望它像往常一样显示,但我只想删除指向这两个页面的链接。
有没有办法做到这一点。
请帮忙。
最合适的回答,由SO网友:Pratik Patel 整理而成
我已经更新了您的代码,请尝试此操作,如果有任何疑问,请告诉我
<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>