【发布时间】:2017-01-26 22:13:19
【问题描述】:
噢噢噢男孩。所以我在这里有这个非常hacky的PHP,但我正在自学wordpress主题开发项目。
尝试集成this rad gradientMaps API,发现了一个奇怪的错误。当我将 js 函数应用于 PHP 构建的元素时,除非我从 html 元素的末尾删除 > 并允许它吞下下一个元素的开始标记(在这种情况下,“
我已经研究了好几个小时,是的,我尝试以新的方式重建我的 PHP,但这是它似乎为我呈现的唯一方式:
<?php
$args = array( 'numberposts' => 6, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
echo '<div class="recent-posts flexbox">';
foreach ($postslist as $post) : setup_postdata($post);
echo "<div class=\"flex-section-3 rpost-thumb\" style=\"background-image: url(";
the_post_thumbnail_url();
// reference point here
echo ")\">";
?>
<h4 class="rpost-category">
<?php es_entry_category(); ?>
</h4>
就像我说的,hacky。
当我添加我的类以在元素上运行 gradientMap javascript 时,控制台中会显示以下内容:
<div class="flex-section-3 random-grad rpost-thumb" style="background-image: url("http://localhost:8000/wp-content/uploads/2016/12/20161222_203726-1200x675.jpg"); filter: url("#filter-1485467730713");" <h4 data-gradientmap-filter="filter-1485467730713">
Category <!-- this is the text result of es_entry_category() -->
<div class="rpost-meta">
<div class="rpost-meta-wrapper">
...
据我所知,问题在于 js 正在添加更多样式属性,而我的 \" 就在我评论的参考点之后关闭 style="" 属性,然后所有渐变图的东西都添加到那里。但是我不能真正失去 style="background..." 业务而不失去动态背景 url 功能(php 函数 the_post_thumbnail_url)。我用谷歌搜索了我的脸,我无法弄清楚。
所以 A) 是否有一些我完全遗漏的明显解决方案? 和 B) 是否有其他 PHP 语法可以用来清理这个荒谬的回声和静音引号网络,并希望以这种方式解决我的问题?
这里是我的jsfiddle 了解更多信息。非常感谢我能在这方面获得任何帮助!
【问题讨论】:
-
看起来
<div class="recent-posts flexbox">在循环之后缺少一个结束</div>。不确定这是否有助于解决问题。 -
检查和双重检查,绝对不是这样。在 PHP 代码中有两个 div 会使小提琴读起来好像 div 开始和结束标记没有对齐,但它们确实对齐。不过感谢您的支持!
标签: javascript php wordpress-theming gradient