Archived topic
Include php code on static page using GP sections ... ?
4 replies · Started by lock-e73 on June 17, 2015
Hi,
Just a quick question, and again I apologise if it's been asked or answered before! I'm creating a static landing page using the GP sections plugin and was wondering how I go about including the most recent blog post in one of the sections? I've tried adding the following code but it essentially comments the php out.
<?php
global $post;
$myposts = get_posts('numberposts=1&category=3');
foreach($myposts as $post) :
?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endforeach; ?>
Any help would be very much appreciated!
Thanks,
lock-e73
Hi there,
WordPress doesn't allow for PHP to be executed through the content editor.
You might be better off using something like this: https://wordpress.org/plugins/display-posts-shortcode/
Then you can use a shortcode to display your most recent blog posts :)
Hi Tom,
Ah, that would explain a lot! :)
Thanks for the pointer to the plugin. I'd actually had a look at that one as well as this one - - which also includes shortcodes and ability to customise with CSS. Will have a bit more of a play with both and see what I can do.
Once again thanks for your quick response!
Cheers,
lock-e73
Hrmm ... stripped the link to the other plugin for some reason. Here 'tis again - Recent Posts Widget Extended
Thanks!
That's a good one as well, but requires a widget area unless you use a plugin like "Widget Shortcode".
