Black Friday sale! Get up to 25% off GP Premium! Learn more ➝

[Resolved] Full width title for specific categories and posts

Home Forums Support [Resolved] Full width title for specific categories and posts

Home Forums Support Full width title for specific categories and posts

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #109325
    Are Martin

    I was wondering if it´s possible to do like described in the thread below; and have a full width title (and meta)….

    http://generatepress.com/forums/topic/full-width-title-on-single-post-page/

    ….but make the title display full width only for specified categories and posts instead of all posts and pages?

    It would be really great if you were able to show me how to make this possible!

    Mvh

    Are Martin Kallåk

    #109462
    Tom
    Lead Developer
    Lead Developer

    Do-able! Tough, but do-able 😉

    First, we’ll remove the page title from a specific single post:

    add_filter( 'the_title', 'generate_remove_post_titles', 10, 2 );
    function generate_remove_post_titles( $title, $id = null )
    {
    
    	global $post, $generate_content_filter_completed;
    	
    	if ( $generate_content_filter_completed ) {
    		return $title;
    	}
    	
    	// Remove the title on our single post with the ID "10" and "20"
    	// Add as many IDs as you like into the array, separated by commas
    	if ( is_single( array( 10, 20 ) ) && in_the_loop() && $title == $post->post_title )
    		return '';
    	
    	// For everything else, return the title as it should be
    	return $title;
    }
    
    add_filter( 'the_content', 'generate_content_filter_completed' );
    function generate_content_filter_completed( $content ) 
    {
    	global $generate_content_filter_completed;
    	$generate_content_filter_completed = true;
    	return $content;
    }

    Then we’ll make some CSS adjustments:

    .postid-10 .entry-content,
    .postid-20 .entry-content {
          margin-top: 0;
    }
    
    .postid-10 .entry-header,
    .postid-20 .entry-header {
          display: none;
    }

    Alright, so we’ve removed the title from our two posts (10 and 20).

    Now, we’ll add our title and meta for these posts into the After Header hook:

    add_action('generate_after_header','generate_add_post_title_below_header');
    function generate_add_post_title_below_header()
    { 
    	// Add the single post IDs we want to target to the array below, separated by commas
    	if ( is_single( array( 10, 20 ) ) ) : ?>
    		<div class="page-header-content generate-page-header generate-content-header">
    			<div class="inside-page-header-container inside-content-header grid-container grid-parent">
    				<header class="entry-header">
    					<?php the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' ); ?>
    					<div class="entry-meta">
    						<?php generate_posted_on(); ?>
    					</div><!-- .entry-meta -->
    				</header><!-- .entry-header -->
    			</div>
    		</div>
    	<?php endif;
    }

    That’s the jist of it.

    Not the easiest thing to do, but it works! 🙂

    #112011
    Are Martin

    Thanks! Might be to advanced for me though 🙂

    #112034
    Tom
    Lead Developer
    Lead Developer

    Definitely pretty custom.

    I may look into including this as a feature in the Page Header add-on down the road 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.