Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6782343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:43:48+00:00 2026-05-26T16:43:48+00:00

I basically want to show some php if it’s inside the category work, I

  • 0

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'>&rarr; View all work</a>

    </section> <!-- end work -->
";
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:43:49+00:00Added an answer on May 26, 2026 at 4:43 pm

    PHP is a templating language, use it as such:

    <?php // Outputting related work if in work category
      if ( in_category( 'work' )) { 
    ?>
    
        <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'>&rarr; View all work</a>
    
        </section> <!-- end work -->
    <?php
    }
    ?>
    

    Code that is not enclosed in <?php ?> tags is output as is to the browser. Every time the webserver discovers a <?php starting tag it gives control to the PHP interpreter which then executes the code enclosed in that tags.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some php conditional logic...basically I want to use jQuery to show or
Bascially I want to know the best way to hide/show an ASP.NET control from
Basically I want do the following: ls -l[+someflags] (or by some other means) that
I want to dynamically hide/show some of the columns in a NSTableView, based on
I need some help with creating a regex for my php script. Basically, I
My datasource is XML (sharepoint list). I basically want to show the date formatted
I basically want to use link_to to link to the index method of a
I basically want to do this: grep 'example.com' www_log > example.com.YYYY-MM-DD-H:i:S.log ...with of course
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I basically want to be able to deploy multiple versions of the same EAR

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.