Easy Custom Content Types in WordPress and loops on home page with CCTM

So I use a WordPress plugin CCTM to create custom fields in posts for each custom site. With CCTM you can create pretty much any type of field you require for your site. Check it over here: Custom Content Type Manager

As you can see you can create custom fields for the posts type, or create a custom content type.

What I usually do is create custom fields an add it to the posts type and viola, custom video, image, link, relation, and lots more in the posts type, for me to edit and manipulate as I choose, but this left me with an altered post type which wasn’t ideal as I have come to realise.

So lately after a conversation with some real dope developers they raised the issue of having a custom content type and having the usual posts type as per normal, something I haven’t thought of.

So the mission was to create Custom Content Types required for the site and keeping the post type original. Having the Custom content type loop on the home page, e.g: A Real Estate site that needs a custom type that displays properties, and also wanting to have the blog functionality. Adding the custom fields to the posts field would throw out the sites styling and make it difficult for user when adding content to the site.

I didn’t see it in the CCTM forum or in the instruction video he has. So some Google’ing and I found what I was looking for. Creating a Custom Content Type loop in the index.php page.

Move the original Posts loop to where ever it is required, and create the Custom Content Type loop like this:
(My custom content type was called: product)

<?php wp_reset_query(); ?>
    $query = new WP_Query( array( ‘post_type‘ => ‘product‘ ) );
    if ( $query->have_posts() ) :
        while ( $query->have_posts() ) : $query->the_post(); ?>
            <h1><a href=”<?php echo get_permalink(); ?>”><?php the_title(); ?></a></h1>
            <?php the_author(); ?>
            <?php the_post_thumbnail(); ?>
            <?php the_excerpt(); ?>
        <?php endwhile;

The above code creates a new loop for the custom Type you created and pulls in the default fields that you can select when creating the content type, and will link to your new custom Type page.

Go ahead and customise and edit as needed. Pull in the fields you need for the home page and it will link to the full page.

This is for my own reference but I hope it helps others out there.
And thanks to developdaly for the answer!

Leave a Reply

Your email address will not be published. Required fields are marked *