8/14/2018 - 11:55 AM

WordPress | Articles with custom classes

You can add your own custom classes to a article in WordPress using an array. See snippet below.

This example also uses a custom multi-choice Select field, and outputs them to an array. The array is then added to post_class.

    // Get all entries from the sector list
    $sectors = get_field('sector_select'); $sectorList = implode(' ', $sectors); $sectorList = strtolower($sectorList);

    $classes = array (

<article <?php post_class($classes); ?>>
    <h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <?php get_template_part('templates/entry-meta'); ?>
  <div class="entry-summary">
    <?php the_excerpt(); ?>