【问题标题】:Wordpress tag auto closeWordpress 标签自动关闭
【发布时间】:2012-10-01 16:04:21
【问题描述】:

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

【问题讨论】:

    标签: wordpress tags wordpress-theming


    【解决方案1】:

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

    &lt;a href="#"&gt;&lt;div&gt;...&lt;/div&gt;&lt;/a&gt; 是有效的 html 5。

    【讨论】:

      【解决方案2】:

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

      我不知道使用# 作为您的href 是实际代码的一部分还是您为简化而做的事情,但如果那是实际代码并且您附加了onclick 或其他东西到a,您可以将其附加到div,它也可以正常工作。

      【讨论】:

      • 我在我的 div 上附加了 onclick 触发器,这解决了问题,但是内联 js 的样式不合适,所以我想通过仅使用 html 标记使 div 成为链接
      • 您可以让div 接受click 事件而不使用内联脚本,请参阅developer.mozilla.org/en-US/docs/DOM/element.addEventListener -- 或者如果您的网站有jQuery,api.jquery.com/click
      • 我同意,即使是听众也会这样做,但我想尽可能省略 js;)
      猜你喜欢
      • 2013-09-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-16
      • 2018-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多