Pressbooks\Taxonomy::getFrontMatterType PHP Method

getFrontMatterType() static public method

Return the first (and only) front-matter-type for a specific post
static public getFrontMatterType ( $id ) : string
$id
return string
    static function getFrontMatterType($id)
    {
        $terms = get_the_terms($id, 'front-matter-type');
        if ($terms && !is_wp_error($terms)) {
            foreach ($terms as $term) {
                return $term->slug;
                break;
            }
        }
        return 'miscellaneous';
    }

Usage Example

Esempio n. 1
0
 /**
  * Adds front matter, resets the page numbering on the first loop,
  * romanizes the numeric style
  *
  * @param array $contents
  */
 function addFrontMatter(array $contents)
 {
     $first_iteration = true;
     $page_options = array('pagenumstyle' => 'i', 'margin-left' => 15, 'margin-right' => 15);
     foreach ($contents as $front_matter) {
         // safety
         $type = \Pressbooks\Taxonomy::getFrontMatterType($front_matter['ID']);
         if ('dedication' == $type || 'epigraph' == $type || 'title-page' == $type || 'before-title' == $type) {
             continue;
             // Skip
         }
         // only reset the page number on first iteration
         true == $first_iteration ? $page_options['resetpagenum'] = 1 : ($page_options['resetpagenum'] = 0);
         // assumes the array of book contents is in order
         if ('front-matter' != $front_matter['post_type']) {
             return;
         }
         if (!empty($front_matter['post_content'])) {
             $this->addPage($front_matter, $page_options, true, true);
             $first_iteration = false;
         }
     }
 }
All Usage Examples Of Pressbooks\Taxonomy::getFrontMatterType