1

Wordpress 更正了帖子和模板特定文件中的 html 标记。我正在开发一个模板,我想要实现的是在<a href"#"></a>标签中包装一个 div。

在放置 foreach 循环之前,然后再添加一些 php 和 html 标记,然后在 foreach 循环结束之前粘贴到结束标记中。wordpress 的作用是在 href 字符串标签之后自动添加结束标签,删除正确放置的结束标签,使链接为空。

他是我输入的内容:

    <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;"
4

2 回答 2

4

只是想评论一下,在 HTML 5 中将块级元素包装在内联元素中是完全可以的。

<a href="#"><div>...</div></a>是有效的 html 5。

于 2012-10-03T00:16:23.483 回答
1

<a href="#"><div>...</div></a>是无效的 HTML。div内联元素 ( ) 内不应该有块级元素( a)。WordPress 可能会试图保护您免受这种情况的影响。

我不知道使用#as yourhref是实际代码的一部分还是只是为了简化而做的事情,但是如果那是实际代码并且您将一个onclick或其他内容附加到,则a可以改为将其附加到div也可以。

于 2012-10-02T05:03:40.853 回答