jp29997

There is, literally, something wrong with my brain, so bear with me on this.

I am modifying a theme for my honeys blog. The section I'm about to quote  is for an individual post's page,it iterates through every category assigned to the post and displays recent posts from those categories. She wants to exclude 2 categories from this list.
the current code looks like

<?

php

 
// this is where 10 headlines from the current category get printed  
if ( is_single() ) :
global $post;
$categories = get_the_category();
foreach ($categories as $category):
?>
<li><h2>More from this category</h2>
<ul class="bullets">
<?

php

 
$posts = get_posts('numberposts=10&category='. $category->term_id);
foreach($posts as $post) :
?>
<li><a href="<?

php

  the_permalink(); ?>"><?

php

  the_title(); ?></a></li>

<?

php

  endforeach; ?>



OK,so I tried to do this

<?

php

 
// this is where 10 headlines from the current category get printed  
if ( is_single() ) :
global $post;
$categories = get_the_category();
foreach ($categories as $category)
$exclude = array("Spotlight","Featured");
if(!in_array($categories->cat_name,$exclude)):
?>
<li><h2>More from this category</h2>
<ul class="bullets">
<?

php

 
$posts = get_posts('numberposts=10&category='. $category->term_id);
foreach($posts as $post) :
?>
<li><a href="<?

php

  the_permalink(); ?>"><?

php

  the_title(); ?></a></li>
<?

php

  endif; ?>
<?

php

  endforeach; ?>


But, I get a blank sidebar. I would convert everything to curly braces--not sure I'm using the colons right with an if inside a foreach and do my dumbass CS 131 debug steps, but if I do that she'll eventually give a big sigh and say forget it, basically afraid I'm going to destroy her sidebar, and rightfully so. So could somebody help a brother out?

The get_the_category function is specified at http://codex.wordpress.org/Template_Tags/get_the_category

DangerMouse

Maybe a small
typo
 ? Wouldnt it be $category->cat_name rather than: "if(!in_array($categories->cat_name,$exclude))" ?

DM

jp29997

calling it a
typo
  is the kindest thing anyone has said to me all day  Applause

anyway, it didn't work but i think you are correct that i was stepping through the wrong array

i think i also had the endif in the wrong position

i switched to cat_ID instead

this is what i have now still no go:

<?

php

 
// this is where 10 headlines from the current category get printed  
if ( is_single() ) :
global $post;
$categories = get_the_category();
foreach ($categories as $category)
$exclude = array('135','14');
if(!in_array($category->cat_ID,$exclude)):
?>
<li><h2>More from this category</h2>
<ul class="bullets">
<?

php

 
$posts = get_posts('numberposts=10&category='. $category->term_id);
foreach($posts as $post) :
?>
<li><a href="<?

php

  the_permalink(); ?>"><?

php

  the_title(); ?></a></li>

<?

php

  endforeach; ?>
<?

php

  endif; ?>





perkiset

I just hate that coding style... the WP people really screwed up when they chose to stay with that rather than moving on.

To debug, I'd echo the test array and every iteration to see what

PHP

  is evaluating... I think it's simply a problem with the not-in-array and you'll see it as soon as you dump each iteration out.

<edit>also, you might consider putting error_reporting(E_ALL) at the top to make sure there's no other issues that are causing the problem</edit>


Perkiset's Place Home   Politics @ Perkiset's