• Custom post types
  • Post metadata
  • Custom taxonomies

Registering the Music Album Post Type

<?php
/*
Plugin Name: Music Collection Post Types
Plugin URI: http://example.com
Description: Creates the music_album post type.
Version: 0.1
*/
 
/* Set up the post types. */
add_action( 'init', 'ssd_music_collection_register_post_types' );
 
/* Registers post types. */
function ssd_music_collection_register_post_types() {
 
    /* Set up the arguments for the 'music_album' post type. */
    $album_args = array(
        'public' => true,
        'query_var' => 'music_album',
        'rewrite' => array(
            'slug' => 'music/albums',
            'with_front' => false,
        ),
        'supports' => array(
            'title',
            'thumbnail'
        ),
        'labels' => array(
            'name' => 'Albums',
            'singular_name' => 'Album',
            'add_new' => 'Add New Album',
            'add_new_item' => 'Add New Album',
            'edit_item' => 'Edit Album',
            'new_item' => 'New Album',
            'view_item' => 'View Album',
            'search_items' => 'Search Albums',
            'not_found' => 'No Albums Found',
            'not_found_in_trash' => 'No Albums Found In Trash'
        ),
    );
 
    /* Register the music album post type. */
    register_post_type( 'music_album', $album_args );
}
 
?>

Registering new taxonomies: Genre and Artist After you add the preceding code, you ’ ll be presented with two new submenu items under the Albums menu item in the admin, labeled Artists and Genres.

<?php
 
/* Set up the taxonomies. */
add_action( 'init', 'ssd_music_collection_register_taxonomies' );
 
/* Registers taxonomies. */
function ssd_music_collection_register_taxonomies() {
 
    /* Set up the artist taxonomy arguments. */
    $artist_args = array(
        'hierarchical' => false,
        'query_var' => 'album_artist', 
        'show_tagcloud' => true,
        'rewrite' => array(
            'slug' => 'music/artists',
            'with_front' => false
        ),
        'labels' => array(
            'name' => 'Artists',
            'singular_name' => 'Artist',
            'edit_item' => 'Edit Artist',
            'update_item' => 'Update Artist',
            'add_new_item' => 'Add New Artist',
            'new_item_name' => 'New Artist Name',
            'all_items' => 'All Artists',
            'search_items' => 'Search Artists',
            'popular_items' => 'Popular Artists',
            'separate_items_with_commas' => 'Separate artists with commas',
            'add_or_remove_items' => 'Add or remove artists',
            'choose_from_most_used' => 'Choose from the most popular artists',
        ),
    );
 
    /* Set up the genre taxonomy arguments. */
    $genre_args = array(
        'hierarchical' => true,
        'query_var' => 'album_genre', 
        'show_tagcloud' => true,
        'rewrite' => array(
            'slug' => 'music/genres',
            'with_front' => false
        ),
        'labels' => array(
            'name' => 'Genres',
            'singular_name' => 'Genre',
            'edit_item' => 'Edit Genre',
            'update_item' => 'Update Genre',
            'add_new_item' => 'Add New Genre',
            'new_item_name' => 'New Genre Name',
            'all_items' => 'All Genres',
            'search_items' => 'Search Genres',
            'parent_item' => 'Parent Genre',
            'parent_item_colon' => 'Parent Genre:',
        ),
    );
 
    /* Register the album artist taxonomy. */
    register_taxonomy( 'album_artist', array( 'music_album' ), $artist_args );
 
    /* Register the album genre taxonomy. */
    register_taxonomy( 'album_genre', array( 'music_album' ), $genre_args );
}
 
?>

Using a Taxonomy with Posts When using taxonomy with posts, you ’ ll generally be listing the taxonomy terms for the given post alongside some or all the content of the post. This would allow viewers to note there is a taxonomy for the post and allow them to fi nd related posts by a given taxonomy term.

<?php
 
add_action( 'init', 'ssd_music_album_register_shortcodes' );
 
function ssd_music_album_register_shortcodes() {
 
    /* Register the [music_albums] shortcode. */
    add_shortcode( 'music_albums', 'ssd_music_albums_shortcode' );
}
 
function ssd_music_albums_shortcode() {
 
    /* Query albums from the database. */
    $loop = new WP_Query(
        array(
            'post_type' => 'music_album',
            'orderby' => 'title',
            'order' => 'ASC',
            'posts_per_page' => -1,
        )
    );
 
    /* Check if any albums were returned. */
    if ( $loop->have_posts() ) {
 
        /* Open an unordered list. */
        $output = '<ul class="music-collection">';
 
        /* Loop through the albums (The Loop). */
        while ( $loop->have_posts() ) {
 
            $loop->the_post();
 
            /* Display the album title. */
            $output .= the_title(
                '<li><a href="' . get_permalink() . '">',
                '</a></li>',
                false
            );
 
        }
 
        /* Close the unordered list. */
        $output .= '</ul>';
    }
 
    /* If no albums were found. */
    else {
        $output = '<p>No albums have been published.';
    }
 
    /* Return the music albums list. */
    return $output;
}
 
?>

A POST TYPE AND TAXONOMY PLUGIN It enables users to create new music albums and organize the albums by genre and artist.

  • The fi rst step you take is creating a new fi le in your plugins directory named ssd-music-collection.php and adding your plugin header at the top of this fi le.
  • The next step is to create the music_album post type, which was outlined in the Registering a Post Type section.
  • The fi nal step of the process is creating the taxonomies for the music_album post type: album_artist and album_genre. How to register a taxonomy was covered in the Registering a Custom Taxonomy section.
  • At this point, you have entire plugin with minimal code that creates and organizes a new type of content within WordPress. All that ’ s left is adding widgets , creating shortcodes, ...

One comment

#134
Saturday, September 27, 2014 11:44 AM
Furniture And Paintings Are Womens Collection When you buy art online, it is not really investment that first comes to mind most especially if it is not wall painting. It is always for the reason of aesthetics or simply collection. People have a habit of collecting what interest them. It is like jewelry. Do you think women panicbuy for diamonds set in platinum for investment when the last thing they want is to lose sight of them? This goes the same for art. Art lovers cannot resist artworks for sale posted online or art sold somewhere in the mall and this is because for mere collection. Although there is this justification for the money spent that one day the collection will be resold, doubling or tripling what was spent on them. This can also be true but there is nothing truer than the satisfaction collecting gives. People have different interests that fascinate them. Collecting becomes a hobby that aside from making the collector satisfied, psychologically speaking it becomes a good stressreliever, too. Although, it cannot be denied that art like wall painting is a big money back after sometime; the guarantee of course comes along with good maintenance or preservation of the artwork. Furniture made of rare hardwood is another collection among women. These are like wall paintings, too, when it comes to amount that needed to be spent when one desires to have a piece. Women drool over furniture just like how they want diamonds all over her. In collecting furniture, those that are made beautiful but of no value is waste of money. These are the ones that are made of ply or just wood particles. But furniture just like artworks for sale that we see over the net can be cheap or very expensive depending on the materials and on how well they are crafted. With wall paintings on the other hand, it is very seldom that we see ones that are cheap in price. And If we bumped into one, it would not necessarily mean that the materials used in painting are cheap but most probably, the artist is just beginning in his or career or simply put, the creator of the artwork has not made a name yet as opposed to furniture which a piece can cost an arm and leg without considering who designs and manufactures it. These two, wall paintings and furniture, are women's collection and fascination for home use. It is innate to women to create beauty wherever she goes. How much more if we speak of her own dwelling! She will not collect stamps or Hasbro toys just like men do. She makes sure that her collection benefits the home front and making your surrounding comfortable, conducive, and beautiful is for women never a luxury but a necessity. This is why men who cannot respect this fact about women should better live somewhere else.

Leave a Comment

Fields with * are required.

Please enter the letters as they are shown in the image above.
Letters are not case-sensitive.