0

当我在浏览器中查看网页的源代码时,我看到页面的一部分周围有很多空白区域。我似乎无法阻止这一点。下面是我正在使用的代码。

html页面中调用的函数:

function query_single($posttype, $poststatus, $paidvalue, $taxtype, $value) {

/* Custom Query for a state, county, or city to display dentist with a single taxonomy query. This displays the results of the loop in taxonomy-dealercity.php, taxonomy-dealerstate.php, taxonomy-dealercounty.php, taxonomy-auctioncity.php, taxonomy-auctionstate.php, taxonomy-auctioncounty.php */

global $wp_query;
$wp_query = new WP_Query();
 $args = array(
   'post_type' => $posttype,
   'post_status' => array($poststatus),
   'orderby' => 'rand', 
   'posts_per_page' => 30,
   'meta_query' => array(
      array(
          'key' => 'wpcf-paid',
          'value' => array($paidvalue),
          'compare' => 'IN',
      )
  ),
'tax_query' => array(
        array(
            'taxonomy' => $taxtype,
            'field' => 'slug',
            'terms' => $value
        )
    )
);
return $wp_query->query($args);
}

带有 html 和 php 的 taxonomy-state.php 页面:

<div class="co7">
 <?php /*Based on type of page a custom h1 and page text is shown*/

 echo "<h1 class=\"title\">$geo_no_dash Destist - Find a Dentist in $geo_no_dash</h1>";

 echo "<p><small>Search for Dentist in $geo_no_dash with our comprehensive $geo_no_dash    Dentist catalog. Find a Dentist in $geo_no_dash by city, state, county</small></p>";?>

 <?php
 /* This function found in the themes function.php file gets dentist which are used in   the first wordpress loop which will show only paid dentist. */

query_single('dealers', 'publish', '1', $taxtype, $value);
 ?>

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

 <?php /* Retrieve relevant dentist information with get_post_meta.  Function   get_dealer_brands gets each dentist brands via a function added in the theme function.php file.  Last section echos out dentist listings.*/

 $address=get_post_meta($post->ID, 'wpcf-street_address', TRUE); 
 $city=get_post_meta($post->ID, 'wpcf-city', TRUE); 
 $state=get_post_meta($post->ID, 'wpcf-state_abbreviation', TRUE); 
 $zip=get_post_meta($post->ID, 'wpcf-zip_code', TRUE); 
 $phone=get_post_meta($post->ID, 'wpcf-phone_number', TRUE); 
 $paid=get_post_meta($post->ID, 'wpcf-paid', TRUE);
 get_each_dealer_brand()?>

 <ul class="ullisting">
 <?php if($paid==1)
 {
echo "<li><p class=\"plisting\"><strong><a href=\"";the_permalink(); echo "\">";the_title();echo "</a></strong></p></li>";
echo "<li><p class=\"plisting\">$address | $city, $state $zip</p></li>";
echo "<li><p class=\"plisting\">P: $phone</p></li>";
    echo "<li><p class=\"listing\"><span><small>$brands_list</small></span></p></li>";
}?>
</ul>

在浏览器中查看源代码时,浏览器空白在每个之间 ul class="ullisting,为 4 到 7 行空白。

我正在重建我的 wordpress 安装,所以我现在没有一个活生生的例子。但这是我得到的输出:

<pre><code>

 <!--Start Side Left Co7-->

 <div class="co7">
 <h1 class="title">Texas Dentist - Find Dentist in Texas</h1><p><small>Search for a Dentist in Texas with our comprehensive Dentist catalog.</small></p>



<ul class="ullisting">
<li><p class="plisting"><strong><a href="http://www.test.com/dealers/dentist1/">Dentist  1</a></strong></p></li><li><p class="plisting">g | g, g g</p></li><li><p class="plisting">P: h</p></li><li><p class="listing"><span><small>Gosmile</small></span> </p></li></ul>







<ul class="ullisting">
<li><p class="plisting"><strong>Dentist 2</strong></p></li><li><p class="plisting">26 main | Spring, TX 77090</p></li><li><p class="plisting">P: 7146122454</p></li><li><p class="listing"><span><small>Brightsmile</small></span></p></li></ul>



<ul class="ullisting">
<li><p class="plisting"><strong>Dentist 3</strong></p></li><li><p class="plisting">35 Main st | Houston, Tx 777090</p></li><li><p class="plisting">P: 1</p></li><li><p class="listing"><span><small>Pro Whitening</small></span></p></li></ul>

4

2 回答 2

1

每当您像以前一样退出 PHP 时,这些换行符都会发送到浏览器。

于 2013-01-25T19:06:46.203 回答
0

空白没什么大不了的。但是,如果这对您来说意义重大,请执行以下操作。更改此代码:

 <ul class="ullisting">
 <?php if($paid==1)
 {
echo "<li><p class=\"plisting\"><strong><a href=\"";the_permalink(); echo "\">";the_title();echo "</a></strong></p></li>";
echo "<li><p class=\"plisting\">$address | $city, $state $zip</p></li>";
echo "<li><p class=\"plisting\">P: $phone</p></li>";
    echo "<li><p class=\"listing\"><span><small>$brands_list</small></span></p></li>";
}?>
</ul>

对此:

<?php 
echo "<ul class="ullisting">";
 if($paid==1)
 {
echo "<li><p class=\"plisting\"><strong><a href=\"";the_permalink(); echo "\">";the_title();echo "</a></strong></p></li>";
echo "<li><p class=\"plisting\">$address | $city, $state $zip</p></li>";
echo "<li><p class=\"plisting\">P: $phone</p></li>";
    echo "<li><p class=\"listing\"><span><small>$brands_list</small></span></p></li>";
}

echo "</ul>";
?>

问题似乎是,既然您有一个页面,其中有纯 HTML 元素与 php 代码混合以“回显”内容,那么只需强制 PHP 回显内容,以便您知道间距符合您的喜好。

但总的来说,我忍受着这样的间距问题,因为无论如何这是编码的副作用;除非您在行距上完全强迫症,否则它永远不会是纯粹的,我认为这不值得付出努力。

于 2013-01-25T19:08:30.717 回答