• Resolved revistataller9

    (@revistataller9)


    Hi, I created a child for the Gateway theme and was able to enable the post formats. Now I’m trying to edit the CSS in a way only my image posts use a full width template. I already read and tried a lot of threads here and in other forums but the solutions they post don’t work for me. At this point I should say I’m the Jon Snow of coding. I know NOTHING. So, if you’d be kind to provide me with full specifications on how to achieve this, it would be much appreciated.

    Here’s a link to my website , and here is a link to an image post

    Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hi Jon ??

    Great job using a Child Theme, you’re already heading in the right direction!

    You’re going to need a bit more than CSS to achieve what you want with your image Posts. What you want is a post format specific template for your image posts. To understand a bit more how this works, take a look at the Template Hierarchy, which is how WordPress determines which template file to use on your site:

    https://developer.www.ads-software.com/themes/basics/template-hierarchy/

    https://developer.www.ads-software.com/themes/basics/template-hierarchy/#single-post

    So, for your image Posts:

    1. Create a new template file in your Child Theme and name it single-image.php
    2. Copy the code from single.php (or whatever file your theme uses for single posts) and paste it into your new single-image.php file.
    3. Update the comment at the top to note that this file is for the Image Post Format.
      Remove the sidebar code, which is everything inside:
      <div class=”large-3 large-offset-1 columns”>
      …some code here…
      </div>
    4. Change
      <div class=”large-8 columns”>
      TO:
      <div class=”large-12 columns”>
    5. Save your changes

    That should give you a full width template, just for your image Posts.

    Let me know if that works, or if we need to fine tune it a bit.

    Thread Starter revistataller9

    (@revistataller9)

    Hi Christi! Thanks for the answer!
    Unfortunately it’s still not working. The new code looks like this:

    <?php
    /**
     * The template for displaying all image 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(); ?>

    Maybe I’ve messed up somewhere?

    From what I can see, that should work. What did you name the file, and can you confirm that it is directly inside your child theme folder?

    I’ll also try installing that theme and making a child theme on one of my test sites. Can you walk me through the steps you took to enable Post formats?

    Thanks!

    Thread Starter revistataller9

    (@revistataller9)

    I named the file single-image.php as you suggested but, from looking at the template hierarchy chart, shouldn’t the file be named {mimetype}.php? or maybe, given all my image posts will be in the same category, is better if I rename the file category-{category id}.php?
    I’m trying those options out and will let you know what happens

    Thank you!

    Thread Starter revistataller9

    (@revistataller9)

    Still nothing ??
    Also tried page-{slug}.php and attachment.php
    Is possible for the theme to override the hierarchy?

    I’ve come to realize that almost anything is possible, but I wouldn’t think the theme would be doing that. I’m having a little server trouble at the moment (tune up went a bit sideways) but as soon as I am able to, I’ll install that theme, make a Child Theme and repeat your steps. Give me a day or two, it might be Saturday before I can really dive into it.

    Thread Starter revistataller9

    (@revistataller9)

    Hey Christi! Any news on the template issue?
    I dived further into it and tried new names to the file but to no avail.

    I’m thinking maybe the theme sets the posts to be “blog posts” so, according to the hierarchy map, that would derive into single-post.php, then single.php, etc. bypassing the single-{post type}.php branch.
    Maybe I’ve enabled the image type posts in a wrong way? From what it says here: https://codex.www.ads-software.com/Post_Types#Custom_Post_Types, the Custom posts should be enabled in a different way than I did. I simply added this piece of code to my child’s theme functions.php file

    function childtheme_formats(){
         add_theme_support( 'post-formats', array( 'image') );

    Have you found anything else?
    Please let me know!
    Thanks!

    I am sorry I didn’t update you earlier. What I thought would be a couple of days has turned into several days to get my server situation fixed. I’m getting a new server this weekend, so sometime next week I should be able to dig into this a bit more.

    Custom Post Types are different from Post Formats. To quote Mark Jaquith:

    A Post Format is a formatting designation made to a post.

    https://markjaquith.wordpress.com/2010/11/12/post-formats-vs-custom-post-types/

    Here’s a link to info on Post Formats from the Codex:

    https://codex.www.ads-software.com/Post_Formats

    Thanks!

    Thread Starter revistataller9

    (@revistataller9)

    I finally managed to solve this! It turns out it could be done by creating a custom post type. I simply copied the single.php file, and renamed it single-viernes.php (viernes is my custom post type name), then applied what you told me earlier and the magic happened!

    Thanks a lot for your help Christi! ??

    Edit: I just noticed my custom posts don’t appear in my home page along with the other posts. How can I correct this?

    Thread Starter revistataller9

    (@revistataller9)

    Hey Christi! Great news! 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;
      }

    So happy to hear that you got this working for your site. Sorry I wasn’t able to be more help. Give yourself a pat on the back, that is great work!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Full width posts’ is closed to new replies.