我们的开发人员为Wordpress编写了一些模板代码,当这个特定模板应用于wordpress页面时,它基本上采用了措辞并以最整洁的方式呈现在最终用户页面上。
此时,剧本只能显示一个新闻稿'每月,我们希望每月显示多个,但不能这样做。
可以在http://i.stack.imgur.com/tQtlD.png
找到问题的清晰屏幕截图 <?php
/*
Template Name: Press Releases (BETA)
*/
?>
<?php
get_header();
$press_releases = getPressReleases($post->post_content);
?>
<div class="container rayures">
<?php require('search_bar.php'); ?>
<ol class="breadcrumb">
<li><a href="<?php echo get_site_url(); ?>">Home</a></li>
<li><!--[if lt IE 8]> / <![endif]--><a href="#">News</a></li>
<li><!--[if lt IE 8]> / <![endif]--><a href="#">Press Releases</a></li>
</ol>
<div class="panel panel-tab panel-color3">
<div class="panel-heading">
<h3><span class="icon-fleche"></span>Press Releases</h3>
</div>
</div>
<div class="row">
<?php if($press_releases){ ?>
<?php foreach($press_releases as $year => $releases){ ?>
<!-- Pour chaque annee -->
<div class="col-sm-12">
<div id="date<?php echo $year; ?>">
<div class="panel panel-tab panel-color3">
<div class="panel-heading">
<h3 class="panel-title">
<a data-toggle="collapse" data-parent="#date<?php echo $year; ?>" href="#collapse<?php echo $year; ?>">
<strong><?php echo $year; ?></strong>
<span class="glyphicon glyphicon-chevron-down pull-right"></span>
</a>
</h3>
</div>
<div id="collapse<?php echo $year; ?>" class="panel-collapse collapse ">
<div class="panel-body">
<ul class="panel-list small-text">
<?php foreach($releases as $k => $v){ ?>
<li><div class="deco"></div><?php echo $v; ?></li>
<?php } ?>
<a href="#">
</ul>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<?php }else{ ?>
<p>No Press Releases</p>
<?php } ?>
</div>
</div>
<?php get_footer(); ?>
仅供参考:这是我在functions.php
中定义的内容function getPressReleases(){
global $wpdb,$post;
$temp_return = $return = array();
$month=array('January','February','March','April','May','June','July','August','September','October','November','December','June');
preg_match_all('|<a href="(.*)">(.*)</a>|', $post->post_content, $output);
if(!empty($output[2])){
for($i=0;$i<count($output[2]);$i++){
$temp = explode(' ',$output[2][$i]);
for($t=0;$t<count($temp);$t++){
// Annees
if(!array_key_exists($temp[1],$temp_return))$temp_return[$temp[1]]=array();
// Mois
if(!array_key_exists($temp[0],$temp_return[$temp[1]]))$temp_return[$temp[1]][$temp[0]] = $output[0][$i];
}
}
// On trie le retour
krsort($temp_return);
foreach($temp_return as $k => $v){
for($i=0;$i<count($month);$i++){
if(!isset($return[$k]))$return[$k]=array();
//if(!array_key_exists($month[$i],$return[$k]) && array_key_exists($month[$i],$temp_return[$k])){//
if(!array_key_exists($month[$i],$return[$k])){
$return[$k][$month[$i]]=$temp_return[$k][$month[$i]];
}
}
}
return $return;
}else{
return FALSE;
}
}
任何指针都将非常感谢!
答案 0 :(得分:0)
我认为你没有在模板中将$ post声明为全局变量。尝试声明&#34;全球$ post;&#34;在此声明之前 $ press_releases = getPressReleases($ post-&gt; post_content);
希望它能起作用..!