简体   繁体   English

WordPress标签自动关闭

[英]Wordpress tag auto close

Wordpress corrects the html markup in posts and also in template specific files. Wordpress可以更正帖子中以及模板特定文件中的html标记。 I'm working on a template and what I'm trying to achieve is wrap a div in <a href"#"></a> tag. 我正在研究模板,而我想实现的目的是将div包裹在<a href"#"></a>标记中。

Before the foreach loop there is placed, then some more php and html markup and right before the foreach loop ends I paste in the ending tag . 在放置foreach循环之前,再放置一些php和html标记,并且在foreach循环结束之前,我将粘贴在ending标签中。 What wordpress doeas it automatically adds the ending tag right after a href string tag, removes the correctly placed ending tag making the link empty. 做什么的wordpress会自动在href字符串标签之后添加结束标签,删除正确放置的结束标签,使链接为空。

He're is what I type: 他是我输入的内容:

    <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>

And here is what Wordpress ends up saving: 这是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>

I temporarily fixed the issue using some javascript code but its neither good practice nor what I want to have: 我使用一些javascript代码临时修复了该问题,但它既不是好习惯,也不是我想要的:

onclick="location.href='<?php the_permalink();?>';" style="cursor:pointer;"

Just wanted to comment that wrapping a block-level element is inside an inline element is perfectly fine in HTML 5. 只是想评论一下,在HTML 5中,将块级元素包装在内联元素内是完全可以的。

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

<a href="#"><div>...</div></a> is invalid HTML. <a href="#"><div>...</div></a>是无效的HTML。 You're not supposed to have a block-level element ( div ) inside of an inline element ( a ). 您不应该在内联元素( a )内包含块级元素( div )。 WordPress is likely trying to protect you from that. WordPress可能会尝试保护您免受此侵害。

I can't tell if using # as your href is part of the actual code or just something you did for simplification, but if that is the actual code and you're attaching an onclick or something to the a , you could instead attach that to the div and it would work just as well. 我不知道是否将#用作您的href是实际代码的一部分,还是只是为了简化而做的事情,但是如果这是实际代码,并且您要将onclick或其他内容附加到a ,则可以附加该代码到div ,效果也一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM