[英]How create a JSON file and read it on Wordpress
I need to create a JSON file to save a list in it. 我需要创建一个JSON文件来保存列表。 This code has to go inside the Wordpress functions.php file.
此代码必须进入Wordpress functions.php文件。 How can I do it?
我该怎么做?
function ProgramarBorrado(){
?>
<script type="text/javascript">
var day = (new Date).getDate(); //Get today
var month = (new Date).getMonth()+1; //Get this month
var year = (new Date).getFullYear(); //Get this year
var lista = [];
if ((day == 1) && (month == 4) && (year==2019)) { //Push ID on a list
lista.push('#borrar22marc');
}
if ((day == 6) && (month == 4) && (year==2019)) {
lista.push('#borrar6abril');
}
if ((day == 5) && (month == 5) && (year==2019)) {
lista.push('#borrar5maig');
}
if ((day == 19) && (month == 5) && (year==2019)) {
lista.push('#borrar19maig');
}
if ((day == 8) && (month == 6) && (year==2019)) {
lista.push('#borrar8juny');
}
if ((day == 10) && (month == 8) && (year==2019)) {
lista.push('#borrar10agost');
}
lista.forEach(function(element) {
jQuery(element).addClass('borrar-programado');// For each element on the list add a class on the ID
});
</script>
<?php
}
add_action('wp_footer', 'ProgramarBorrado');
the code has to be similar to this. 代码必须与此类似。 Save the variable "lista" on a JSON file
将变量“lista”保存在JSON文件中
如果数组是在javascript中生成的,则可以使用JSON.stringify
var json = JSON.stringify(lista);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.