Wordpress更正了帖子以及模板特定文件中的html標記。 我正在研究一個模板,我試圖實現的是將一個div包裝在<a href"#"></a>
標記中。Wordpress標籤自動關閉
在放置foreach循環之前,先放一些php和html標記,並在foreach循環結束之前粘貼結束標記。 什麼是wordpress doeas會自動在href字符串標籤後面添加結束標籤,刪除正確放置的結束標籤,使鏈接爲空。
He're就是I型:
<li <?php if (get_option('square_portfolio_filter') != "true") { ?> data-id="id-<?php echo $count; ?>" data-type="<?php foreach ($terms as $term) { echo strtolower(preg_replace('/\s+/', '-', $term->name)). ' '; } ?>" <?php ; } ?>>
<a href="#">
<div class="thumbs-animate">
<?php
if (has_post_thumbnail()) {
the_post_thumbnail(array(255,191), array('title' => ''.get_the_title().''));
}
?>
<div class="details">
<h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
<p><?php content('15'); ?></p>
<a href="<?php the_permalink(); ?>">
<?php
if(get_option('square_view_project_link')!="") {
echo get_option('square_view_project_link');
}else {
_e('View Project', 'square_lang');
}
?>
</div>
</div>
</a>
</li>
而且這裏是WordPress的最終節省:
<li <?php if (get_option('square_portfolio_filter') != "true") { ?> data-id="id-<?php echo $count; ?>" data-type="<?php foreach ($terms as $term) { echo strtolower(preg_replace('/\s+/', '-', $term->name)). ' '; } ?>" <?php ; } ?>>
<a href="#"></a>
<div class="thumbs-animate">
<?php
if (has_post_thumbnail()) {
the_post_thumbnail(array(255,191), array('title' => ''.get_the_title().''));
}
?>
<div class="details">
<h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>
<p><?php content('15'); ?></p>
<a href="<?php the_permalink(); ?>">
<?php
if(get_option('square_view_project_link')!="") {
echo get_option('square_view_project_link');
}else {
_e('View Project', 'square_lang');
}
?>
</div>
</div>
</li>
我暫時使用一些JavaScript代碼,但它既不好也不做法固定的問題我想要的:
onclick="location.href='<?php the_permalink();?>';" style="cursor:pointer;"
,我在我的div的onclick附着其觸發解決了這個問題,但是內聯js不是正確的樣式,所以我想通過僅使用html標記來使div成爲鏈接 –
您可以讓'div'接受'click'事件而不訴諸內聯腳本,請參見https: //developer.mozilla.org/en-US/docs/DOM/element.addEventListener - 或者如果你的網站有jQuery,http://api.jquery.com/click/ – smitelli
我同意,即使是聽衆也會這樣做,但我如果可能的話,想省略js樂;) –