Site logo

Archived topic

Blog design for custom posttype

5 replies · Started by Patrick on December 13, 2016

Viewing posts 1–6 of 6

Hi Tom,

how is it possible to use the bloglayout (the archiv/overview page, not the detailpage) for a custom posttype to? I like the same design for my custom posttye as for the blog.

thanks and regards
patrick

Additonal, like to have it as masonry styled boxes

There's a handy filter you can use to apply masonry to your custom post types:

add_filter( 'generate_blog_masonry','generate_adjust_masonry' );
function generate_adjust_masonry( $masonry )
{
    if ( is_post_type_archive( 'portfolio' ) ) :
        return 'true';
    endif;

    if ( is_post_type_archive( 'news' ) ) :
        return 'true';
    endif;

    if ( is_post_type_archive( 'events' ) ) :
        return 'true';
    endif;

    return $masonry;
}

Same with columns:

add_filter( 'generate_blog_columns','generate_adjust_columns' );
function generate_adjust_columns( $columns )
{
    if ( is_post_type_archive( 'portfolio' ) ) :
        return true;
    endif;

    return $columns;
}

I have tried to get this to work, but it does not seem to work with my custom post type page template.
My custom template works, but I know I am doing it the wrong way to get it to work with masonry.
I guess I need to copy the index and content page and then put my custom loop in the content page, is that correct?

Here is my custom template code as it stands.

<?php
/**
* Template Name: Case Studies
*/

get_header(); ?>
<section class="page-padding">

>
<main id="main" <?php generate_main_class(); ?>>
<h1>Case Studies</h1>
<?php do_action('generate_before_main_content'); ?>
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; ?>
<?php // WP_Query arguments
$args = array(
'post_type' => array( 'casestudies' ),
'post_status' => array( 'publish' ),
'posts_per_page' => '10',
'order' => 'DESC',
'orderby' => 'date',
'paged' => $paged,
); query_posts($args);

// The Query
$cases = new WP_Query( $args ); ?>
<?php if ( $cases->have_posts() ) : ?>
<?php while ( $cases->have_posts() ) : $cases->the_post(); ?>

<?php the_post_thumbnail('medium'); ?>
<h2><?php the_title(); ?></h2>
<?php
echo wp_trim_words( get_the_content(), 60, '... Read More' );
?>

<?php endwhile; ?>
<!-- Add the pagination functions here. -->

<?php endif; ?>
<?php wp_reset_query(); ?>
<?php do_action('generate_after_main_content'); ?>
</main><!-- #main -->

<!-- #primary -->
<?php
do_action('generate_sidebars');?>
</section>
<?php get_footer();

This archived topic is closed to new replies.