• Resolved revistataller9

    (@revistataller9)


    Hi everybody!
    I run an architecture magazine, and every other day we invite illustrators to draw something for our site. These posts consist on just an image and a few lines of text for the credits, etc. The thing is, the Gateway theme has a wide sidebar, and the image couldn’t be appreciated fully.
    So I created a child theme, and in the functions.php I added this:

    function childtheme_formats(){
         add_theme_support( 'post-formats', array( 'viernes') );
    }
    add_action( 'after_setup_theme', 'childtheme_formats', 11 );
    
    function remove_more_link_scroll( $link ) {
    	$link = preg_replace( '|#more-[0-9]+|', '', $link );
    	return $link;
    }

    As a result, I now have a custom post type called ‘viernes’ for these image posts. I also created a single-viernes.php file and in it I wrote this:

    <?php
    /**
     * The template for displaying all VIERNES posts.
     *
     */
    
    get_header(); ?>
    
    <div class="row">
    
    	<div id="primary" class="content-area">
    
    		<div class="large-12 columns">
    
    			<main id="main" class="site-main" role="main">
    
    			<?php while ( have_posts() ) : the_post(); ?>
    
    				<?php get_template_part( 'template-parts/content', 'single' ); ?>
    
    				<?php gateway_post_nav(); ?>
    
    				<hr>
    
    				<?php
    					// If comments are open or we have at least one comment, load up the comment template
    					if ( comments_open() || get_comments_number() ) :
    						comments_template();
    					endif;
    				?>
    
    			<?php endwhile; // end of the loop. ?>
    
    			</main><!-- #main -->
    
    		</div><!-- .large-12 -->
    
    	</div><!-- #primary -->
    
    </div><!-- .row -->
    
    <?php get_footer(); ?>

    Now I have a custom post type AND a full width template for those posts. But these custom posts didn’t show on my home page along with the rest ‘standard’ posts. So, in my functions.php I added

    add_filter('pre_get_posts', 'include_my_events');
    function include_my_events($q) {
    
    if ( !is_admin() && is_home() ) {
        $post_types = array('post','viernes');
        $q->set('post_type', $post_types);
    }
    return $q;
    }

    The thing is, this last piece of code messes with the fonts I use and I don′t know why. Now the links on the sidebar, footer and even the ‘Read more’ tag appear unformatted.

    I’ve already tried doing the same thing using regular ‘image’ posts instead of a custom post type, but for whatever reason, the single-image.php nor the image.php files (containing the same code I wrote earlier) seem to have any effect.

    Any help is much appreciated!

Viewing 1 replies (of 1 total)
  • Thread Starter revistataller9

    (@revistataller9)

    As it turns out, the way to achieve this kind of post (I’m talking about regular posts here, not a Custom Post), was to add this piece of code to the functions.php file on my child theme:

    add_action('template_include', 'load_single_template');
      function load_single_template($template) {
        $new_template = '';
    
        // single post template
        if( is_single() ) {
          global $post;
          // 'cat-1' and 'cat-2' are category slugs
    
          if( has_term('cat-1', 'category', $post) ) {
            // use template file single-template-cat-1.php
            $new_template = locate_template(array('single-template-cat-1.php' ));
          }
    
          if( has_term('cat-2', 'category', $post) ) {
            // use template file single-template-cat-2.php
            $new_template = locate_template(array('single-template-cat-2.php' ));
          }
    
        }
        return ('' != $new_template) ? $new_template : $template;
      }
Viewing 1 replies (of 1 total)
  • The topic ‘[Theme: Gateway] Help with custom post types’ is closed to new replies.