Iam creating a theme where i need to work this process.
我创建了一个主题,我需要在这个过程中工作。
I tried in many ways and made a number of search/research but failed to find the way.
我尝试过多种方式并进行了大量的搜索/研究,但未能找到方法。
I asked a similar question before with full details which is at,
之前我问了一个类似的问题,详细信息是,
将Wordpress发布信息分配给PHP数组并将php数组值分配给javascript数组
Please answer on any of the questions. Thank you.
请回答任何问题。谢谢。
1 个解决方案
#1
here is a way to get your posts in many different ways into an array:
这是一种将您的帖子以多种不同方式发布到数组中的方法:
<?php $args = array(
'posts_per_page' => 5,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts_array = get_posts( $args ); ?>
I think Descending order should make it go from the latest post but if not try Ascending.
我认为降序应该从最新的帖子开始,但如果没有尝试升序。
As far as getting your php array into a javascript array it can be done with the push method like so:
至于将你的php数组放入一个javascript数组,可以使用push方法完成,如下所示:
<script type="text/javascript" language="javascript">
var pausecontent = new Array();
<?php foreach($posts_array as $key => $val){ ?>
pausecontent.push('<?php echo $val; ?>');
<?php } ?>
</script>
Anyway hope that helps, should work fine but let me know if you run into any complications
无论如何希望有所帮助,应该工作正常,但如果你遇到任何并发症,让我知道
#1
here is a way to get your posts in many different ways into an array:
这是一种将您的帖子以多种不同方式发布到数组中的方法:
<?php $args = array(
'posts_per_page' => 5,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true
);
$posts_array = get_posts( $args ); ?>
I think Descending order should make it go from the latest post but if not try Ascending.
我认为降序应该从最新的帖子开始,但如果没有尝试升序。
As far as getting your php array into a javascript array it can be done with the push method like so:
至于将你的php数组放入一个javascript数组,可以使用push方法完成,如下所示:
<script type="text/javascript" language="javascript">
var pausecontent = new Array();
<?php foreach($posts_array as $key => $val){ ?>
pausecontent.push('<?php echo $val; ?>');
<?php } ?>
</script>
Anyway hope that helps, should work fine but let me know if you run into any complications
无论如何希望有所帮助,应该工作正常,但如果你遇到任何并发症,让我知道