php - Issue with code used to pull data from posts in wordpress -
a developer of ours wrote template code wordpress , when particular template applied wordpress page takes wording , presents on end-user page in tidy fashion.
at minute, script can display 1 'press release' per month, display multiple per month cannot so.
a clear screenshot of issue can found here 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 $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 $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(); ?>
fyi: here have defined in 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 $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; } }
any pointers appreciated!
i think didn't declare $post global variable in template. try declare "global $post;" before statement $press_releases = getpressreleases($post->post_content);
hope work..!
Comments
Post a Comment