2014-10-11 23 views
0

这是HTML渲染线:空的空间,我怎么可以做的更好

<a href='http://www.1stheme.dev/?frontiles=1946'> 
<article class="post-1946 frontiles type-frontiles status-publish hentry Width_1_Height_1 "   style="width:326px;height:326px;text-align:left;" 
      id="post-1946"> 



    <header> 
    <p class="counter">1 </p> 

     <h2 style=""> 

     Title  </h2> 

     <h4 style=""> 
       </h4> 
    </header> 
       <div class="frontile_hover Width_1_Height_1" 
      style="width:326px;height:326px;" id="post-1946"> 
        </div> 

</article> 
</a> 

的,这是生成它们的PHP:

<?php echo "<a href='"; if ($disable_link) { 
     echo "#' style='cursor:default'>"; 
      } elseif ($custom_link) { 
     echo $custom_link . "'>"; 
      } else { 
     echo $acf_permalink . "'>"; } 
?> 

<article <?php post_class($tile_dimension . ' ' . $shape); ?> 
      style="<?php 
       if ($invisible_tile) {echo "visibility:collapse" . ";";} 
         if ($custom_tile_width) {echo "width:" . $custom_tile_width . "px;";} 
         if (!$custom_tile_width && $tiles_units_width && $GLOBALS['acf_grid_width']) { 
          $custom_tile_width = $tiles_units_width * $GLOBALS['acf_grid_width'] + $GLOBALS['acf_grid_margin'] * ($tiles_units_width -1); 
           echo "width:" . $custom_tile_width . "px;";} 
         if ($custom_tile_height) {echo "height:" . $custom_tile_height . "px;";} 
         if (!$custom_tile_height && $tiles_units_height_ && $GLOBALS['acf_grid_height']) { 
          $custom_tile_height = $tiles_units_height_ * $GLOBALS['acf_grid_height'] + $GLOBALS['acf_grid_margin'] * ($tiles_units_height_ -1); 
           echo "height:" . $custom_tile_height . "px;";}      
       if ($text_font_alignment) {echo "text-align:" . $text_font_alignment . ";";} 
       if ($background_color || $background_image) { 
        echo "background:" . $background_color . " url(" . $background_image . ") center/cover;";} 

        ?>" 
      id="post-<?php the_ID(); ?>"> 
    <?php if (!$invisible_tile) : ?> 



    <header> 
    <p class="counter"><?php echo $wp_query->current_post +1; ?> </p> 
     <?php // the_post_thumbnail('', array('class' => 'th')); ?> 

     <h2 style="<?php 
       if ($title_font_color) {echo "color:" . $title_font_color . ";";} 
       if ($title_font_size) {echo "font-size:" . $title_font_size . ";";} 
       if ($title_margin) {echo "margin:" . $title_margin . ";";} 
       if ($title_font_family) {echo "font-family:" . $title_font_family . ";";} 
       if ($title_line_height) {echo "line-height:" . $title_line_height . ";";} 
       if(is_array($title_font_style) && in_array('bold', $title_font_style)) { 
        echo "font-weight:bold;"; } 
       if(is_array($title_font_style) && in_array('italic', $title_font_style)) { 
        echo "font-style:italic;"; } 
       if ($title_letter_spacing) {echo "letter-spacing:" . $title_letter_spacing . ";";} 

        ?>"> 

     <?php if ($alternative_title) {echo $alternative_title;} else {the_title();} ?> 
     </h2> 

     <h4 style="<?php 
       if ($desc_font_color) {echo "color:" . $desc_font_color . ";";} 
       if ($desc_font_size) {echo "font-size:" . $desc_font_size . ";";} 
       if ($desc_margin) {echo "margin:" . $desc_margin . ";";} 
       if ($desc_font_family) {echo "font-family:" . $desc_font_family . ";";} 
       if ($desc_line_height) {echo "line-height:" . $desc_line_height . ";";} 
       if(is_array($title_font_style) && in_array('bold', $title_font_style)) { 
        echo "font-weight:bold;"; } 
       if(is_array($title_font_style) && in_array('italic', $title_font_style)) { 
        echo "font-style:italic;"; } 
       if ($desc_letter_spacing) {echo "letter-spacing:" . $desc_letter_spacing . ";";}1 

        ?>"> 
     <?php if ($alternative_desc) {echo $alternative_desc;} else {the_excerpt();} ?> 
     </h4> 
    </header> 
     <?php if (!$disable_on_over) : ?> 
     <div class="frontile_hover <?php echo $tile_dimension ?>" 
      style="<?php 
      if ($hover_bkg_color || $hover_bkg_img) { 
       echo "background:" . $hover_bkg_color . " url(" . $hover_bkg_img . ") center/cover;";} 
         if ($custom_tile_width) {echo "width:" . $custom_tile_width . "px;";} 
         if (!$custom_tile_width && $tiles_units_width && $GLOBALS['acf_grid_width']) { 
          $custom_tile_width = $tiles_units_width * $GLOBALS['acf_grid_width'] + $GLOBALS['acf_grid_margin'] * ($tiles_units_width -1); 
           echo "width:" . $custom_tile_width . "px;";} 
         if ($custom_tile_height) {echo "height:" . $custom_tile_height . "px;";} 
         if (!$custom_tile_height && $tiles_units_height_ && $GLOBALS['acf_grid_height']) { 
          $custom_tile_height = $tiles_units_height_ * $GLOBALS['acf_grid_height'] + $GLOBALS['acf_grid_margin'] * ($tiles_units_height_ -1); 
           echo "height:" . $custom_tile_height . "px;";}  
      ?>" id="post-<?php the_ID(); ?>"> 
      <?php echo the_excerpt(); ?> 
     </div> 
     <?php endif; // end disable_on_mouse over?> 
    <?php endif; // end invisible_tile?> 

</article> 
</a> 

此代码作品,但它呈现了太多的空白。 欢迎任何帮助。

我没有太多的话要说,我使用高级自定义字段与wordpress建立一个可定制的主题。对不起所有的代码,但以这种方式,你可以更好地检查我认为。

+0

使用键盘上的Enter键将空白符合您的喜好。 – 2014-10-11 23:19:45

+0

如果你在PHP中断行,它将在源代码中显示换行符。 HTML将多个空格和换行符视为单个空格,而不是由'
'创建的空格和换行符。如果我想要漂亮的源代码,我通常将所有内容连接到一个变量,然后再回显。 – PHPglue 2014-10-11 23:25:32

回答

0

尝试删除在?><?php之间找到的空格。请注意,删除PHP标记中的空格不会更改HTML。

<?php echo "<a href='"; if ($disable_link) { 
     echo "#' style='cursor:default'>"; 
      } elseif ($custom_link) { 
     echo $custom_link . "'>"; 
      } else { 
     echo $acf_permalink . "'>"; } 
?><article <?php post_class($tile_dimension . ' ' . $shape); ?>style="<?php 
       if ($invisible_tile) {echo "visibility:collapse" . ";";} 
         if ($custom_tile_width) {echo "width:" . $custom_tile_width . "px;";} 
         if (!$custom_tile_width && $tiles_units_width && $GLOBALS['acf_grid_width']) { 
          $custom_tile_width = $tiles_units_width * $GLOBALS['acf_grid_width'] + $GLOBALS['acf_grid_margin'] * ($tiles_units_width -1); 
           echo "width:" . $custom_tile_width . "px;";} 
         if ($custom_tile_height) {echo "height:" . $custom_tile_height . "px;";} 
         if (!$custom_tile_height && $tiles_units_height_ && $GLOBALS['acf_grid_height']) { 
          $custom_tile_height = $tiles_units_height_ * $GLOBALS['acf_grid_height'] + $GLOBALS['acf_grid_margin'] * ($tiles_units_height_ -1); 
           echo "height:" . $custom_tile_height . "px;";}      
       if ($text_font_alignment) {echo "text-align:" . $text_font_alignment . ";";} 
       if ($background_color || $background_image) { 
        echo "background:" . $background_color . " url(" . $background_image . ") center/cover;";} 

        ?>" id="post-<?php the_ID(); ?>"><?php if (!$invisible_tile) : ?><header> 
    <p class="counter"><?php echo $wp_query->current_post +1; ?></p><?php // the_post_thumbnail('', array('class' => 'th')); ?><h2 style="<?php 
       if ($title_font_color) {echo "color:" . $title_font_color . ";";} 
       if ($title_font_size) {echo "font-size:" . $title_font_size . ";";} 
       if ($title_margin) {echo "margin:" . $title_margin . ";";} 
       if ($title_font_family) {echo "font-family:" . $title_font_family . ";";} 
       if ($title_line_height) {echo "line-height:" . $title_line_height . ";";} 
       if(is_array($title_font_style) && in_array('bold', $title_font_style)) { 
        echo "font-weight:bold;"; } 
       if(is_array($title_font_style) && in_array('italic', $title_font_style)) { 
        echo "font-style:italic;"; } 
       if ($title_letter_spacing) {echo "letter-spacing:" . $title_letter_spacing . ";";} 

        ?>"><?php if ($alternative_title) {echo $alternative_title;} else {the_title();} ?> 
     </h2><h4 style="<?php 
       if ($desc_font_color) {echo "color:" . $desc_font_color . ";";} 
       if ($desc_font_size) {echo "font-size:" . $desc_font_size . ";";} 
       if ($desc_margin) {echo "margin:" . $desc_margin . ";";} 
       if ($desc_font_family) {echo "font-family:" . $desc_font_family . ";";} 
       if ($desc_line_height) {echo "line-height:" . $desc_line_height . ";";} 
       if(is_array($title_font_style) && in_array('bold', $title_font_style)) { 
        echo "font-weight:bold;"; } 
       if(is_array($title_font_style) && in_array('italic', $title_font_style)) { 
        echo "font-style:italic;"; } 
       if ($desc_letter_spacing) {echo "letter-spacing:" . $desc_letter_spacing . ";";}1 

        ?>"><?php if ($alternative_desc) {echo $alternative_desc;} else {the_excerpt();} ?></h4> 
    </header><?php if (!$disable_on_over) : ?><div class="frontile_hover <?php echo $tile_dimension ?>" style="<?php 
      if ($hover_bkg_color || $hover_bkg_img) { 
       echo "background:" . $hover_bkg_color . " url(" . $hover_bkg_img . ") center/cover;";} 
         if ($custom_tile_width) {echo "width:" . $custom_tile_width . "px;";} 
         if (!$custom_tile_width && $tiles_units_width && $GLOBALS['acf_grid_width']) { 
          $custom_tile_width = $tiles_units_width * $GLOBALS['acf_grid_width'] + $GLOBALS['acf_grid_margin'] * ($tiles_units_width -1); 
           echo "width:" . $custom_tile_width . "px;";} 
         if ($custom_tile_height) {echo "height:" . $custom_tile_height . "px;";} 
         if (!$custom_tile_height && $tiles_units_height_ && $GLOBALS['acf_grid_height']) { 
          $custom_tile_height = $tiles_units_height_ * $GLOBALS['acf_grid_height'] + $GLOBALS['acf_grid_margin'] * ($tiles_units_height_ -1); 
           echo "height:" . $custom_tile_height . "px;";}  
      ?>" id="post-<?php the_ID(); ?>"> 
      <?php echo the_excerpt(); ?></div> 
     <?php endif; // end disable_on_mouse over?><?php endif; // end invisible_tile?></article> 
</a> 
+0

谢谢,我要走了,以后再试,我会回信。但我一直在想,也许创建一个函数(使用它从functions.php)会更干净?我很抱歉,我正在尝试,但我不是程序员我是网页设计师多年,但不是在这个级别,谢谢。比这更干净的功能或某种解决方案的例子将会很有帮助 – Dedalos01 2014-10-12 10:45:18

相关问题