Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Custom Post Types in WordPress

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #165040
    justdan
    Participant

    Hey guys,

    Quick question. I started getting into themeing in WordPress lately. I get a lot of what I’m doing but one area that’s still tricky is custom post types. I can register them in the my functions.php file and I get my added option to my admin bar, but when I try to pull them onto my homepage.php file, I don’t get what I’m after or nothing shows up at all. I know that this is a big area so I won’t ask anyone to tell me how to do it, but if somebody knows of a great link to start me out it’d be very appreciated. I tried numerous google searches and tested many snippets of code, but I still couldn’t get it to work so I thought I’d ask here. Any help is greatly appreciated as always guys. Thank you.

    #165050
    Alen
    Participant
    <?php
        // WP_Query arguments
        $args = array (
            'post_type' => 'YOUR-CUSTOM-TYPE-HERE',
        );
        // The Query
        $the_query = new WP_Query( $args );
        // The Loop
        if ( $the_query->have_posts() ) {
                echo '<ul>';
            while ( $the_query->have_posts() ) {
                $the_query->the_post();
                echo '<li>' . get_the_title() . '</li>';
            }
                echo '</ul>';
        } else {
            // no posts found
        }
        /* Restore original Post Data */
        wp_reset_postdata();
    ?>
    

    Also see this: http://codex.wordpress.org/Post_Types#Template_Files

    And,

    This: http://generatewp.com/

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Other’ is closed to new topics and replies.