我知道有類似的問題,但他們無法真正回答我的問題。我正在構建一個WordPress主題,後端有很多選項。例如,我爲地址製作了hcard可以包含的每個可能值的字段。我在一個查詢中查詢選項,然後我有很多if語句來創建我的html。當然,大多數情況下不需要。很多PHP if語句會減慢我的網站
<?php
$address_settings = get_option('nothing_settings_address'); ?>
<?php if($address_settings[ 'hcard_given_name' ] || $address_settings[ 'hcard_family_name' ]) : ?>
<?php $hcard_title = $address_settings[ 'hcard_given_name' ].' '.$address_settings[ 'hcard_family_name' ]; ?>
<?php elseif($address_settings[ 'hcard_organization' ]) : ?>
<?php $hcard_title = $address_settings[ 'hcard_organization' ]; ?>
<?php endif; ?>
<figure id="vcard-<?php echo $address_settings[ 'hcard_family_name' ]; ?><?php echo $address_settings[ 'hcard_given_name' ]; ?>" class="vcard one-third column" title="<?php echo $hcard_title; ?>" itemtype="http://www.data-vocabulary.org/Person/" itemscope="itemscope">
<!-- Photo -->
<img src="<?php echo $address_settings[ 'hcard_img' ]; ?>" alt="" class="photo" itemprop="photo">
<!-- alt redundant; image labeled by context, leave empty (webaim) -->
<!-- Caption -->
<figcaption>
<!-- Profile -->
<section class="profile">
<!-- Name -->
<?php if($address_settings[ 'hcard_given_name' ] || $address_settings[ 'hcard_family_name' ] || $address_settings[ 'hcard_nickname' ]) : ?>
<header class="n" title="Name">
<?php if($address_settings[ 'hcard_given_name' ] || $address_settings[ 'hcard_family_name' ]) : ?>
<span class="fn" itemprop="name">
<?php if($address_settings[ 'hcard_prefix' ]) : ?>
<span class="honorific-prefix"><?php echo $address_settings[ 'hcard_prefix' ]; ?></span>
<?php endif; ?>
<?php if($address_settings[ 'hcard_given_name' ]) : ?>
<span class="given-name"><?php echo $address_settings[ 'hcard_given_name' ]; ?></span>
<?php endif; ?>
<?php if($address_settings[ 'hcard_middle_name' ]) : ?>
<span class="additional-name"><?php echo $address_settings[ 'hcard_middle_name' ]; ?></span>
<?php endif; ?>
<?php if($address_settings[ 'hcard_family_name' ]) : ?>
<span class="family-name"><?php echo $address_settings[ 'hcard_family_name' ]; ?></span>
<?php endif; ?>
<?php if($address_settings[ 'hcard_suffix' ]) : ?>
<span class="honorific-suffix"><?php echo $address_settings[ 'hcard_suffix' ]; ?></span>
<?php endif; ?>
</span> <!--/ .fn -->
<?php endif; ?>
<?php if($address_settings[ 'hcard_nickname' ]) : ?>
<span class="nickname" itemprop="nickname"><?php echo $address_settings[ 'hcard_nickname' ]; ?></span>
<?php endif; ?>
</header> <!--/ .n -->
<?php endif; ?>
<!-- Category -->
<?php if($address_settings[ 'hcard_cat' ]) : ?>
<section class="category" itemprop="category">
<?php echo $address_settings[ 'hcard_cat' ]; ?>
</section>
<?php endif; ?>
<!-- Links -->
<?php if($address_settings[ 'hcard_note' ]) : ?>
<section class="note" itemprop="note" >
<?php echo $address_settings[ 'hcard_note' ]; ?>
</section>
<?php endif; ?>
<!-- Birthday -->
<?php if($address_settings[ 'hcard_bday' ]) : ?>
<time class="bday" itemprop="bday" >
<?php echo $address_settings[ 'hcard_bday' ]; ?>
</time>
<?php endif; ?>
<!-- Organization -->
<?php if($address_settings[ 'hcard_organization' ] || $address_settings[ 'hcard_unit' ] || $address_settings[ 'hcard_title' ]) : ?>
<div class="org" itemprop="affiliation" title="Organization" itemscope="itemscope" itemtype="http://www.data-vocabulary.org/Organization/">
<?php if($address_settings[ 'hcard_organization' ]) : ?>
<div class="vcard">
<span class="organization-name fn" itemprop="name"><?php echo $address_settings[ 'hcard_organization' ]; ?></span>
<?php if($address_settings[ 'hcard_orga_street' ] || $address_settings[ 'hcard_orga_city' ] || $address_settings[ 'hcard_orga_state' ] || $address_settings[ 'hcard_orga_country' ] || $address_settings[ 'hcard_orga_postal_code' ]) : ?>
<div class="adr" itemprop="address" itemscope="itemscope" itemtype="http://data-vocabulary.org/Address/">
<!-- Address --><?php if($address_settings[ 'hcard_orga_street' ]) : ?>
<span class="street-address" itemprop="street-address"><?php echo $address_settings[ 'hcard_orga_street' ]; ?></span>
<?php endif; ?>
<!-- City --><?php if($address_settings[ 'hcard_orga_city' ]) : ?>
<span class="locality" itemprop="locality"><?php echo $address_settings[ 'hcard_orga_city' ]; ?></span>,
<?php endif; ?>
<!-- State --><?php if($address_settings[ 'hcard_orga_state' ]) : ?>
<?php if($address_settings[ 'hcard_orga_state' ]) :
$orga_state_title = $address_settings[ 'hcard_orga_state' ];
else :
$orga_state_title = $address_settings[ 'hcard_orga_state_short' ];
endif; ?>
<?php if(!$address_settings[ 'hcard_orga_state' ]) :
$orga_state = $address_settings[ 'hcard_orga_state' ];
else :
$orga_state = $address_settings[ 'hcard_orga_state_short' ];
endif; ?>
<abbr class="region" itemprop="region" title="<?php echo $orga_state_title; ?>"><?php echo $orga_state; ?></abbr>
<?php endif; ?>
<!-- Zip --><?php if($address_settings[ 'hcard_orga_postal_code' ]) : ?>
<abbr class="postal-code" itemprop="postal-code" title="<?php echo $address_settings[ 'hcard_orga_postal_code' ]; ?>"><?php echo $address_settings[ 'hcard_orga_postal_code' ]; ?></abbr>
<?php endif; ?>
<!-- Country --><?php if($address_settings[ 'hcard_orga_country' ] || $address_settings[ 'hcard_orga_country_short' ]) : ?>
<?php if($address_settings[ 'hcard_orga_country' ]) :
$orga_country_title = $address_settings[ 'hcard_orga_country' ];
else :
$orga_country_title = $address_settings[ 'hcard_orga_country_short' ];
endif; ?>
<?php if(!$address_settings[ 'hcard_orga_country' ]) :
$orga_country = $address_settings[ 'hcard_orga_country' ];
else :
$orga_country = $address_settings[ 'hcard_orga_country_short' ];
endif; ?>
<abbr class="country-name" itemprop="country-name" title="<?php echo $orga_country_title; ?>"><?php echo $orga_country; ?></abbr>
<?php endif; ?>
<!-- Lat/Lon (Metadata) -->
<!-- I will integrate that later. <span class="geo" itemprop="geo" itemscope="itemscope" itemtype="http://data-vocabulary.org/Geo/">
<abbr class="latitude" itemprop="latitude" title="60.6060606060">60.6060606060</abbr>
<abbr class="longitude" itemprop="longitude" title="-60.6060606060">-60.6060606060</abbr>
</span>-->
</div> <!--/ .adr -->
<?php endif; ?>
</div> <!--/ .vcard -->
<?php endif; ?>
<?php if($address_settings[ 'hcard_unit' ]) : ?>
<span class="organization-unit"><?php echo $address_settings[ 'hcard_unit' ]; ?></span>
<?php endif; ?>
<?php if($address_settings[ 'hcard_title' ]) : ?>
<span class="title" itemprop="title"><?php echo $address_settings[ 'hcard_title' ]; ?></span>
<?php endif; ?>
</div> <!--/ .org -->
<?php endif; ?>
<!-- Location -->
<?php if($address_settings[ 'hcard_street' ] || $address_settings[ 'hcard_city' ] || $address_settings[ 'hcard_state' ] || $address_settings[ 'hcard_country' ] || $address_settings[ 'hcard_postal_code' ]) : ?>
<address class="adr" itemprop="address" title="Location" itemscope="itemscope" itemtype="http://data-vocabulary.org/Address/">
<!-- Address --> <?php if($address_settings[ 'hcard_street' ]) : ?>
<span class="street-address" itemprop="street-address"><?php echo $address_settings[ 'hcard_street' ]; ?></span>
<?php endif; ?>
<!-- City --><?php if($address_settings[ 'hcard_city' ]) : ?>
<span class="locality" itemprop="locality"><?php echo $address_settings[ 'hcard_city' ]; ?></span>,
<?php endif; ?>
<!-- State --><?php if($address_settings[ 'hcard_state' ]) : ?>
<?php if($address_settings[ 'hcard_state' ]) :
$state_title = $address_settings[ 'hcard_state' ];
else :
$state_title = $address_settings[ 'hcard_state_short' ];
endif; ?>
<?php if(!$address_settings[ 'hcard_state' ]) :
$state = $address_settings[ 'hcard_state' ];
else :
$state = $address_settings[ 'hcard_state_short' ];
endif; ?>
<abbr class="region" itemprop="region" title="<?php echo $state_title; ?>"><?php echo $state; ?></abbr>
<?php endif; ?>
<!-- Zip --><?php if($address_settings[ 'hcard_postal_code' ]) : ?>
<abbr class="postal-code" itemprop="postal-code" title="<?php echo $address_settings[ 'hcard_postal_code' ]; ?>"><?php echo $address_settings[ 'hcard_postal_code' ]; ?></abbr>
<?php endif; ?>
<!-- Country --><?php if($address_settings[ 'hcard_country' ] || $address_settings[ 'hcard_country_short' ]) : ?>
<?php if($address_settings[ 'hcard_country' ]) :
$country_title = $address_settings[ 'hcard_country' ];
else :
$country_title = $address_settings[ 'hcard_country_short' ];
endif; ?>
<?php if(!$address_settings[ 'hcard_country' ]) :
$country = $address_settings[ 'hcard_country' ];
else :
$country = $address_settings[ 'hcard_country_short' ];
endif; ?>
<abbr class="country-name" itemprop="country-name" title="<?php echo $country_title; ?>"><?php echo $country; ?></abbr>
<?php endif; ?>
<!-- Lat/Lon (Metadata) -->
<!-- I will integrate that later. <span class="geo" itemprop="geo" itemscope="itemscope" itemtype="http://data-vocabulary.org/Geo/">
<abbr class="latitude" itemprop="latitude" title="30.3030303030">30.3030303030</abbr>
<abbr class="longitude" itemprop="longitude" title="-30.3030303030">-30.30303030</abbr>
</span>-->
</address> <!--/ .adr -->
<?php endif; ?>
<!-- Contact -->
<?php if($address_settings[ 'hcard_url' ]) : ?>
<a class="url" href="<?php echo $address_settings[ 'hcard_url' ]; ?>"><?php echo $address_settings[ 'hcard_url' ]; ?></a>,
<?php endif; ?>
<?php if($address_settings[ 'hcard_postal_code' ]) : ?>
<a href="mailto:<?php echo $address_settings[ 'hcard_email' ]; ?>" class="email"><?php echo $address_settings[ 'hcard_email' ]; ?></a>
<?php endif; ?>
<?php if($address_settings[ 'hcard_work' ] || $address_settings[ 'hcard_private' ] || $address_settings[ 'hcard_mobile' ] || $address_settings[ 'hcard_fax' ]) : ?>
<ul itemscope="itemscope" itemtype="http://www.data-vocabulary.org/Organization/">
<?php if($address_settings[ 'hcard_private' ]) : ?>
<li class="tel"><abbr class="type" title="home pref">Home:</abbr> <abbr class="value" itemprop="tel" title="<?php echo $address_settings[ 'hcard_private' ]; ?>"><a href="tel:<?php echo $address_settings[ 'hcard_private' ]; ?>"><?php echo $address_settings[ 'hcard_private' ]; ?></a></abbr></li>
<?php endif; ?>
<?php if($address_settings[ 'hcard_work' ]) : ?>
<li class="tel"><abbr class="type" title="work">Office:</abbr> <abbr class="value" itemprop="tel" title="<?php echo $address_settings[ 'hcard_work' ]; ?>"><a href="tel:<?php echo $address_settings[ 'hcard_work' ]; ?>"><?php echo $address_settings[ 'hcard_work' ]; ?></a></abbr></li>
<?php endif; ?>
<?php if($address_settings[ 'hcard_mobile' ]) : ?>
<li class="tel"><abbr class="type" title="mobile">Mobile:</abbr> <abbr class="value" itemprop="tel" title="<?php echo $address_settings[ 'hcard_mobile' ]; ?>"><a href="tel:<?php echo $address_settings[ 'hcard_mobile' ]; ?>"><?php echo $address_settings[ 'hcard_mobile' ]; ?></a></abbr></li>
<?php endif; ?>
<?php if($address_settings[ 'hcard_fax' ]) : ?>
<li class="tel"><abbr class="type" title="fax">Fax:</abbr> <abbr class="value" itemprop="tel" title="<?php echo $address_settings[ 'hcard_fax' ]; ?>"><a href="tel:<?php echo $address_settings[ 'hcard_fax' ]; ?>"><?php echo $address_settings[ 'hcard_fax' ]; ?></a></abbr></li>
<?php endif; ?>
</ul>
<?php endif; ?>
</section> <!--/ .profile -->
</figcaption> <!--/ .figcaption -->
</figure>
我想我的主題非常快。沒有它可能的那麼快。但速度足以被稱爲「快速主題」。我在我的主題中做這樣的事情。所有這些陳述都可以減慢速度嗎?
if語句不會減慢網站下來感知,它的循環和數據庫/文件系統訪問減慢腳本 – 2013-05-14 08:11:50
我不知道workpress ..你必須經常啓動,停止PHP?你可以使用開關\案例 – 2013-05-14 08:14:15