Hi, can anyone help me solve the following problem?
I’m trying to create a widget within WordPress using the following PHP code:
<?php
class Engine_Latest_Posts_Widget extends WP_Widget {
function __construct() {
parent::__construct('engine-latest-posts-widget', 'Engine Latest Posts Widget');
}
function widget($args, $instance) {
echo '
<li class="widget-container" id="widget-latest-posts">
<div class="widget-header"><h3>Latest Blog Posts</h3></div>
<div class="widget-content">
<div class="coda-slider-wrapper">
<div class="coda-slider preload" id="coda-slider-5">
HELLO
<?php query_posts("cat=4&showposts=5"); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="coda-panel">
<div class="coda-panel-content">
<h6><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h6>
</div>
</div>
<?php endwhile;?>
</div><!-- .coda-slider -->
</div><!-- .coda-slider-wrapper -->
</div>
</li>';
}
function form($instance)
{
}
}
register_widget('Engine_Latest_Posts_Widget');
?>
I suspect that the problem is caused because I’m attempting to use code like “<?php query_posts(“cat=4&showposts=5”); ?>” within an “echo”, which is just printing this in the source code, rather than actioning it as PHP code.
But… I don’t really know PHP and I don’t know how to fix it. I’ve attempted to learn what I need to know via several tutorials, but nothing I have tried has worked.
Any suggestions? Thank you!