There's this "Recent Posts" widget, that should output only posts in category 'News' (ID 26)

So I tried this:

<?php $t =& peTheme(); ?>
<?php $content =& $t->content; ?>
<?php list($data) = $t->template->data(); ?>

<?php if (in_category('26')):?> <!-- Line I added -->

<?php if (!empty($data->title)): ?>
<h3><?php echo $data->title; ?></h3>
<?php endif; ?>

<?php while ($content->looping()): ?>
<span class="small"><?php $content->date(); ?></span>
<a class="comments-num small" href="#"><?php $content->comments(); ?></a>
<p><?php echo $t->utils->truncateString(get_the_excerpt(),$data->chars); ?>
<?php endwhile; ?>

<?php if (!empty($data->link)): ?>
<a class="more-link" href="<?php echo $data->url ?>"><?php echo $data->link ?></a>
<?php endif; ?>
<?php endif; ?> <!-- Line I added -->

But it outputs a blank space where it was the widget. Is there a way I can filter to only show recent posts from category 26 there?

  • 1
    We would probably have to see all the code for this Recent Posts widget. Is it a plugin? Can you provide a link? Sep 15, 2013 at 4:46
  • Charles, this is the full code! It's weird, right? - I just added those two lines Sep 15, 2013 at 13:57
  • peTheme() is not a WordPress function. Since most people viewing this will not know what it does or what it returns, this code is not complete. Sep 15, 2013 at 22:03

1 Answer 1


It looks like you're mixing the Wordpress in_category() function with plugin / theme code that isn't setting up a standard WP Query or post object. So you can't use in_category().

Use var_dump($content); and var_dump($data); to see if either of those objects have a 'category' property for the content. Use that in an if statement instead, e.g.: if($data->category-id == 26)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.