如何在我的自定义帖子类型中取消图像的‘alt’属性?

时间:2013-07-31 作者:Laniakea

我已经创建了一个自定义的帖子类型,但现在我似乎不知道如何在项目打开后释放图像名称(在图像下)。当一个项目被点击时,除了图片之外,我只需要显示项目名称和推特链接。Link 前往试验现场。

在我的功能中。php我有:

<?php

require_once(\'portfolio-type.php\');
add_filter(\'excerpt_length\', \'my_excerpt_length\');

function my_excerpt_length($length) {
return 25; 
}

add_filter(\'excerpt_more\', \'new_excerpt_more\');  
function new_excerpt_more($text){  

return \' \';  
}  

function portfolio_thumbnail_url($pid){
$image_id = get_post_thumbnail_id($pid);  
$image_url = wp_get_attachment_image_src($image_id,\'screen-shot\');  
return  $image_url[0];  
}
?>
在投资组合类型中。php:

 <?php

 if ( function_exists( \'add_theme_support\' ) ) { 
add_theme_support( \'post-thumbnails\' );
set_post_thumbnail_size( 270, 170, true ); // Normal post thumbnails
add_image_size( \'screen-shot\', 720, 540 ); // Full size screen
 }

 add_action(\'init\', \'portfolio_register\');  

 function portfolio_register() {  
 $args = array(  
    \'label\' => __(\'Portfolio\'),  
    \'singular_label\' => __(\'Project\'),  
    \'public\' => true,  
    \'show_ui\' => true,  
    \'capability_type\' => \'post\',  
    \'hierarchical\' => false,  
    \'rewrite\' => true,  
    \'supports\' => array(\'title\', \'editor\', \'thumbnail\')  
   );  

register_post_type( \'portfolio\' , $args );  
 }  

register_taxonomy("project-type", array("portfolio"), array("hierarchical"  =>  true, "label" => "Project Types", "singular_label" => "Project Type",   "rewrite" => true));
 ?>
最后在我的索引中。php我有:

<div id="posts" class="row isotope">

                      <?php if (have_posts()) : while (have_posts()) : the_post(); ?>  

                          <?php  
                              $title= str_ireplace(\'"\', \'\', trim(get_the_title()));  
                              $desc= str_ireplace(\'"\', \'\', trim(get_the_content()));  
                          ?>     

                          <div class="item post item span4 isotope-item">

                            <a class="project-wrp fancybox" title="<?=$title?>" rel="lightbox[work]" href="<?php print portfolio_thumbnail_url($post->ID) ?>"><div class="profile-photo"><div class="profile-icon">&#0102;</div><?php the_post_thumbnail(); ?></div>  
                            <div class="project-name"><?php echo $title; ?></div>
                            <div class="project-client"><?php echo $desc; ?></div>
                            </a>
                          </div>  
                      <?php endwhile; endif; ?>  


</div>

1 个回复
最合适的回答,由SO网友:s_ha_dum 整理而成

图像名称和“Tweet”链接之间的类似描述的元素看起来像是从图像中提取的alt 属性我没有看到实际生成该部分的代码——我在你发布的内容中找不到“Tweet”。但是,您可以通过传递一个空的alt属性来消除这种情况,如下所示:

the_post_thumbnail(array(\'230\',\'170\'),array(\'alt\' => \'\'));

结束