Hej,我会保持简短。我想在 WP 循环中输出这个:
Support
Category1
-Post1
-Post2
Category2
-PostA
-PostB
-PostC
Run Code Online (Sandbox Code Playgroud)
所以我想按位于自定义帖子类型中的类别订购帖子 - support(感谢 Types 插件创建,链接: ujeb.se/A4zqZ )。
我有这个:
<?php
$args = array('post_type' => 'support');
$query = new WP_Query($args);
while($query -> have_posts()) : $query -> the_post(); ?>
<p><?php the_category(); ?></p>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<p><?php the_content(); ?></p>
<?php endwhile; ?>
Run Code Online (Sandbox Code Playgroud)
我$query从我的自定义帖子类型 ( support) 中存储了所有必要的帖子,但我在按类别显示它们时遇到了问题。我相信我需要某种东西,foreach但我真的想不通。有什么建议?
/edit/
当前显示如下:
Support, Category1
Post1
---
Support, Category2
PostA
---
Support, Category1
Post2
etc.
Run Code Online (Sandbox Code Playgroud) 我读到在 Cypress 中我不应该使用它await,也不需要它,因为您可以通过链接删除嵌套。这里我有一个cy.fixure嵌套 incy.origin嵌套 in cy.session,有没有办法把它展平?
cy.session([], () => {
cy.visit("")
cy.origin("https://my-address.com", () => {
cy.fixture("user").then((user) => {
cy.get("#username").type(user.username)
cy.get("#password").type(user.password)
})
cy.get("button[type='submit']").click()
cy.url().should("equal", "/login-success")
})
})
Run Code Online (Sandbox Code Playgroud)
编辑
这不是关于常规 javascript 的问题,它是Cypress特定的,正常的 async/await 在这里不起作用。
我做错了但我看不清楚(这可能是因为我的AngularJS技能很低).我的HTML中有一个简单的ng-repeat:
<ul>
<li ng-repeat="fot in fotografia"><img src="{{fot.path}}"></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
这是我的app.js:
myApp.controller('homeController', function($scope) {
// fotografia = []; is here only because I get an error otherwise,
// which means my later for loop can't access the $scope.fotografia
fotografia = [];
$scope.fotografia = [
{path:'img/fotografia/fot_1.jpg'},
{path:'img/fotografia/fot_2.jpg'}
];
// I want to add more images with this:
for(var i=0; i<5; i++) {
fotografia.push({
path: 'img/fotografia/fot_'+[i]+'.jpg'
});
}
});
Run Code Online (Sandbox Code Playgroud)
Ng-repeat与我在数组中已有的2个图像(fot_1.jpg,fot_2.jpg)一起工作正常.循环就是问题所在.如何将更多项目推入我的阵列?
我会直截了当。我有两个数组:
fruits = ["Banana", "Apple"];
fruitsSpecified = ["Big Banana", "Banana Small", "Black Apple", "Big Orange"];
Run Code Online (Sandbox Code Playgroud)
我正在寻找的结果:
newArray = ["Big Banana", "Banana Small", "Black Apple"];
Run Code Online (Sandbox Code Playgroud)
因此,我想检查fruitsSpecified字符串是否包含的一部分fruits并将这些结果放入新数组中。我怎么做?我发现的所有答案都过于复杂,只寻找完全匹配的内容(例如,数组1中的“ Apple”和数组2中的“ Apple”)。
到目前为止,我有:
function testFunction() {
newArray = [];
for (i = 0; i < fruitsSpecified.length; i++) {
myResult = fruitsSpecified.indexOf(fruits[i]);
newArray.push(myResult);
}
console.log(newArray);
}
Run Code Online (Sandbox Code Playgroud)
由于只能找到完全匹配的内容,因此显然不起作用。
我已经检查了这些问题(但是发现它们太复杂了,我相信/希望有一个更简单的解决方案):
查找项目是否在JavaScript数组中的最佳方法?
如何检查数组是否在JavaScript中包含对象?
谢谢!
我需要一些帮助来找出创建一个customAttribute允许简单编辑切换的最佳方法.这是我正在寻找的:
<tr toggle-edit>
<td edit-hide>${model.name}</td>
<td edit-show><input type="text" value.bind="model.name"></td>
<td><button edit-trigger>Edit</button></td>
</tr>
Run Code Online (Sandbox Code Playgroud)
所以基本上我想要一个customAttribute名称toggleEdit,它将查找edit-trigger属性并向其添加一个事件监听器,它将使变量真/假,并根据它将显示或隐藏具有edit-hide/ 的元素edit-show.
我宁愿不去DOM内部element找到这些属性,因为它感觉jQuerish,这是可以实现的吗?
我希望有一个像这样的customAttribute,因为我至少有10个元素将使用一个编辑按钮并为每个元素都有一个变量然后使用if.bind似乎是一个坏主意.我总是可以在模板内部进行,click.delegate="myShowVar = !myShowVar"但据我所知,在html中放置逻辑是一种不好的做法(来自角度背景).
我会添加一个plunker/codepen,但由于整个编译和库依赖,这似乎不是一件容易的事.
非常感谢任何想法.