Eric Wood Eric Wood - 1 year ago 52
PHP Question

Adding PHP code within shortcode return value

I have a custom post type (called releases) being fed into a page template on my site. I also want to take a chunk of this code, limit it to three items, and make a shortcode out of it so I can use it in the middle of page templates.

Here's the code I'd like to add:

<?php query_posts( array( 'post_type' => 'releases','posts_per_page' => 3 ) ); ?>
<h3><?php the_title(); ?> <span class="viewlink"><?php the_content(); ?></span></h3>


And here's the code I'm trying to add it into:

function home_press( $atts, $content = null ) {
return ' I WANT TO ADD THE CODE HERE ';
}
add_shortcode('press', 'home_press');


I feel like I've seen this done before, but I can't remember how to make this work. Any help would be much appreciated!

Thanks.

Answer Source

**Learn how the loop works here ==> THE LOOP

Learn how query_posts work here ==> Query Posts

Learn how shortcodes work here ==> Add SHortcode**

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download