我正在为WordPress构建一个自定义模板,并且我在几个地方使用了PHP if if语句,例如页脚JS中的以下示例.它工作正常,但我想知道这是否被认为是"坏习惯",如果是这样,有什么更好的方法来处理它?
<script type="text/javascript">
var $submenu = $('.submenu');
// SUBMENU animation
<?php if ( in_category('Collection') == false ) { ?> // if not a Collection subpage
$('.menu li a').each(function() {
if ( $(this).text() == 'Collection' ) { // If is Collection link show submenu on hover
$(this).mouseenter(function() {
$submenu.slideDown();
});
} else { // else close submenu on hover over other menu links
$(this).mouseenter(function() {
$submenu.slideUp();
});
}
});
$('.nav').mouseleave(function() { // close submenu
$submenu.slideUp();
});
<?php } else …Run Code Online (Sandbox Code Playgroud) 我是Bolt的新手,我正试图在记录的图像列表中获取图像的原始宽度.'image'的变量只包括文件名,标题,id,顺序和文件,因此image.width | image不做任何事情.我宁愿不使用缩略图(宽度,高度)方法,除非我可以使用它来访问图像的全尺寸尺寸,而不是裁剪版本.
https://docs.bolt.cm/record-and-records#imagelist
https://docs.bolt.cm/templatetags#imageinfo
有没有办法在imagelist循环中使用imageinfo()来获取宽度和高度,还是有更好的方法去做?谢谢你的帮助!
{% setcontent myprojects = 'projects' %}
{% for project in myprojects %}
<div class="slide">
{% for image in project.imagelist %}
<img src="{{ image.filename|image }}" width="{{ image.width|image }}" height="{{ image.height|image }}">
{% endfor %}
</div>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)