Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #35114
    Jack S
    Participant

    Hello,

    I’m building a site with a custom post type, and have hooked in the template file for the single post as follows:

    function get_custom_post_type_template($single_template) {
    	global $post;
    	if ($post->post_type == 'event') {
    		$single_template = dirname(__FILE__).'/single-event.php';
    	}
    	return $single_template;
    }
    add_filter('single_template','get_custom_post_type_template');

    This is because I do not wish to modify the x theme directory at all, including adding files.

    The issue I’m having is that there I have no control over the page title for single-event.php as it is already set by the theme previously via get_header(). There is a title there but it’s whatever’s defined in the theme options for the title of the blog page, rather than the current post title (like the_title()), which is what I need.

    For clarification: this is what I need to change:

    <header class="x-header-landmark">
          <div class="x-container-fluid max width">
            <div class="x-landmark-breadcrumbs-wrap">
              <div class="x-landmark">       
                  <h1 class="h-landmark"><span>Blog Title</span></h1>      
              </div>
            </div>
          </div>
        </header>

    What would be the best way to fix this?

    Thank you,
    J

    #35254
    Rad
    Moderator

    Hi Jack,

    Thank you for posting in! You could create another header on your child theme.
    The best way is copying some x theme files.

    For example.

    1. Copy x theme’s header.php and rename it into header-event.php, and place it in your child theme.

    Then you can just call it like :

    get_header('event');

    2. In your header-event.php code, you should change it into :

    <?php x_get_view( x_get_stack(), 'wp', 'header-event' ); ?>

    3. Then copy your /x/framework/views/{STACK}/wp-header.php into /x-child-{STACK}/framework/views/{STACK}/wp-header-event.php

    4. Edit your wp-header-event.php and find something like :
    <?php x_get_view( '{STACK}', '_landmark-header' ); ?>
    and edit it into :
    <?php x_get_view( '{STACK}', '_landmark-header-event' ); ?>

    5. Copy your /x/framework/views/{STACK}/_landmark-header.php into /x-child-{STACK}/framework/views/{STACK}/_landmark-header-event.php

    6. Then edit your new _landmark-header-event.php 🙂

    Hope this helps.

    #35333
    Jack S
    Participant

    Hello,

    Thanks for your reply. Unfortunately, I’m not using a child theme (I haven’t ever) – I am just using X, and I have my custom post type & the templates in a plugin. I’m going to try the instructions you’ve provided however, only with the plugin rather than a child theme. My only concern is that I want to be able to update the X theme version in the future – will that be a problem if I copy and paste the code from header.php? Would I have to update the custom header file every time I update the theme?

    Thanks,
    Jack

    #35493
    Support
    Member

    Hi,

    Thank you for the update.

    I’m sorry but you can’t preserve this modification without using a child theme. You can edit the title for the custom post type on framework > views > {stack} > _landmark-header.php. Find this code on line 34:

    <?php if ( is_singular( 'x-portfolio' ) ) : ?>
    
                  <h1 class="h-landmark"><span><?php echo get_theme_mod( 'x_portfolio_title' ); ?></span></h1>
    
                <?php else : ?>
    
                  <h1 class="h-landmark"><span><?php echo get_theme_mod( 'x_renew_blog_title' ); ?></span></h1>
    
                <?php endif; ?>
    

    Replace it with this:

     <?php if ( is_singular( 'x-portfolio' ) ) : ?>
    
                  <h1 class="h-landmark"><span><?php echo get_theme_mod( 'x_portfolio_title' ); ?></span></h1>
    
                <?php elseif ( is_singular( 'event' ) ) : ?>
                
                  <h1 class="h-landmark"><span><?php $title = get_the_title(); echo $title; ?></span></h1>
                  
                 <?php else : ?>
    
                  <h1 class="h-landmark"><span><?php echo get_theme_mod( 'x_renew_blog_title' ); ?></span></h1>

    I hope that helps.

    #880586
    awschro
    Participant
    This reply has been marked as private.
    #881379
    Rupok
    Member

    Hi @awschro

    Thanks for updating the thread. It’s a pretty old thread so it would be better if you open a new thread and provide your information there in a separate private reply. It will help to keep to forum clean, updated and useful for others.

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-35114 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>