Title: [Plugin: WP Carousel] &#8211; execute PHP code in widget?
Last modified: August 19, 2016

---

# [Plugin: WP Carousel] – execute PHP code in widget?

 *  Resolved [callender](https://wordpress.org/support/users/jimcallender/)
 * (@jimcallender)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-wp-carousel-execute-php-code-in-widget/)
 * Hi there,
 * I want to display the ‘recent comments’ in wp-carousel.
 * `<ol class="commentlist"><?php wp_list_comments(array('style' => 'ol')); ?></
   ol>`
 * The ‘costumized content’ widget does not execute this php.
 * Any ideas for executing php code within the WP-Carousel greatly appreciated!
 * Regards,
 * Jim C.

Viewing 1 replies (of 1 total)

 *  Thread Starter [callender](https://wordpress.org/support/users/jimcallender/)
 * (@jimcallender)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-wp-carousel-execute-php-code-in-widget/#post-1665448)
 * Hello,
 * I had a similar problem with posts. I wanted to show the number of published 
   posts in a post and I wanted this number to be updated every time I publish a
   new post. The solution was to use a keyword (something like, for instance, [LAST_COMMENTS])
   and replace that keyword later with filters and actions.
 * But with WP Carousel you have it easier. First, select a keyword, for instance,[
   LAST_COMMENTS]. Then modify your WP Carousel’s theme and replace this line:
 *     ```
       <?php foreach ($items as $i_id => $item): ?>
       ```
   
 * With these three lines:
 *     ```
       <?php foreach ($items as $i_id => $item): ?>
       <?php $replacement = '<ol class="commentlist">'.wp_list_comments(array('style' => 'ol')).'</ol>'; ?>
       <?php str_replace('[LAST_COMMENTS]', $replacement, $item['DESC']); ?>
       ```
   
 * The only problem you will get is that wp_list_comments prints by default the 
   comments (instead of returning them), so you need to set a callback function 
   to return the content in order to allow the variable $replacement to store the
   comments. You have more info about this in the codex.

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: WP Carousel] – execute PHP code in widget?’ is closed to new
replies.

 * 1 reply
 * 1 participant
 * Last reply from: [callender](https://wordpress.org/support/users/jimcallender/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/plugin-wp-carousel-execute-php-code-in-widget/#post-1665448)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
