I basically want to show some php if it’s inside the category work, I know how to do the if else statement and the output php on their own but not quite sure how to combine the two, if someone could enlighten me it would be much appreciated. The basic code is below, i’m guessing i’m not allowed to have a <?php inside a <?php?
Many thanks!
<?php // Outputting related work if in work category
if ( in_category( 'work' )) {
echo "
<section class='work'>
<h2>Also of interest</h2>
<?php query_posts('category_name=work&posts_per_page=3&order=DSC&offset=1&orderby=ID');
if (have_posts()) : while (have_posts()) : the_post(); ?>
<article>
<a href='<?php the_permalink() ?>'>
<?php the_post_thumbnail();?>
<h3><?php the_title(); ?></h3>
<span>Redesign</span>
<?php the_excerpt($strip_teaser); ?>
</a>
</article>
<?php endwhile; endif; wp_reset_query();?>
<a class='all' href='/work'>→ View all work</a>
</section> <!-- end work -->
";
}
?>
PHP is a templating language, use it as such:
Code that is not enclosed in
<?php ?>tags is output as is to the browser. Every time the webserver discovers a<?phpstarting tag it gives control to the PHP interpreter which then executes the code enclosed in that tags.