Note that there are some explanatory texts on larger screens.

plurals
  1. POPhp syntax for echoing multiple classes with a space between them
    primarykey
    data
    text
    <p>I'm am working on a Wordpress custom template and I'm filtering post by their classes. Since Wordpress displays a LOT of unnecessary classes when I put <code>&lt;?php post_class(); ?&gt;</code> in a page, <br/>( here is what it gives me <code>class="post-54 post type-post status-publish format-standard hentry category-3d category-web"</code> ) I'm trying to simplify that by echoing only the categories that relate to the post.</p> <p><br/> <strong>EDIT:</strong> <br/>This is what calls the post in my page <code>&lt;?php query_posts( 'showposts=99' ); ?&gt;</code></p> <p>Then this piece of code</p> <pre><code>&lt;li class="&lt;?php if ( in_category('category-3d')) { echo "3d"; } if ( in_category('category-animation')) { echo "animation"; } if ( in_category('category-motion')) { echo "motion"; } if ( in_category('category-shortfilm')) { echo "shortfilm"; }?&gt;"&gt;&lt;/li&gt; </code></pre> <p>give me this <code>&lt;li class="motion"&gt;&lt;/li&gt;</code> if my post is in the "motion" category.</p> <p>The problem is that <strong>if my post is in several categories, only the first is echoed</strong>... How can I tell WP to echo ALL the names of the categories my post is affected to, while adding a space between them?</p> <p>Since I am a beginner in php syntax, I'm still learning how to get such a simple thing working in a clean and effective way (i.e. without writing 16 lines of code !)... Can someone help me on this one? <br/><br/><br/> <strong>SECOND EDIT:</strong><br/> Ok I'm still trying to figure out why, but today, my piece of code (above) is working and echoes all my listed classes, but without space between them... So to make my classes work, I'm adding a space at the end of the echo part like this <code>{ echo "3d "; }</code>. But I feel like it's a dirty way to make things work... <br/><br/> <strong>How to add a space between each class tag in the proper way?</strong> I'm aiming for something like this <code>foreach $categories as $cat { echo $cat . " "; }</code> but where $categories and $cat would refer to each "if" statement.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload