WordPress.org

Forums

Hueman
How to style custom post type (4 posts)

  1. Renji
    Member
    Posted 1 year ago #

    Hello Alexander,

    Firstly, I'd like to thank you for this amazing free theme.

    My question is - I've added a custom post type in my WordPress installation, in its category page all posts show up with 100% width (screenshot). I'd like to have those posts in the same grid view as the default category archive. How do I fix this?

    Regards,
    Renji

  2. Alexander Agnarson
    Member
    Theme Author

    Posted 1 year ago #

    Glad you like it!

    If you check the index.php file, you will see that the content loop is wrapped in:

    <div class="post-list group">
    <?php $i = 1; echo '<div class="post-row">'; while ( have_posts() ): the_post(); ?>
    <?php get_template_part('content'); ?>
    <?php if($i % 2 == 0) { echo '</div><div class="post-row">'; } $i++; endwhile; echo '</div>'; ?>
    </div><!--/.post-list-->

    Try adding that around your custom post type archive loop as well.

  3. Renji
    Member
    Posted 1 year ago #

    Actually I did try that, but still doesn't work.

    I have created the post type following instructions in the Codex. Also, I am showing articles listed in that post type on the homepage using below code:

    add_filter( 'pre_get_posts', 'my_get_posts' );
    function my_get_posts( $query ) {
    	if ( is_home() && $query->is_main_query() || is_category())
    		$query->set( 'post_type', array( 'post', 'page', 'rhyme' ) );
    	return $query;
    }

    Everywhere the posts listed in 'rhyme' appear the same as seen in the previous screenshot.

  4. mfapsj
    Member
    Posted 1 year ago #

    I added this line to CSS because I had the same (or a similar) problem:

    .post-list .post,
    .post-list .project,
    .post-list .page { width: 50%; float: left; }

    PROJECT is the name of my custom post type

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic