This is searchable archive of our old support forums, which operated from 2012 - 2016. To find out how to get support for your current theme, please visit our support page.

Unable to load template for custom post type in Alyeska child theme

  • Creator
    Topic
  • #4026
    iohannis
    Participant

    Hi,

    I am having trouble loading a template file from my child theme. I’ve found some instructions, but it’s not working.

    The template file is located in the child theme root, called ‘content-anmeldelse.php’

    Here is my functions.php code:

    // Add theme support for all post formats
    add_theme_support( 'post-formats', array( 'anmeldelse' ) );

    // Use content-{post_format}.php for listing posts
    function ocb_template_parts( $parts ) {

    // Determine post format where relevant
    $post_format = '';
    if( ! is_404() && ! is_search() )
    $post_format = get_post_format();

    // Adjust template parts
    $parts['index'] = $post_format;
    $parts['list'] = $post_format;
    $parts['list_paginated'] = $post_format;
    $parts['list_slider'] = $post_format;
    $parts['single'] = $post_format;
    $parts['archive'] = $post_format;
    $parts['anmeldelse'] = 'anmeldelse';

    return $parts;
    }
    add_filter( 'themeblvd_template_parts', 'ocb_template_parts' );

    I have no idea why it’s not loading. I tested $parts['anmeldelse'] = $post_format; as well, but no result.

    Please help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #4038
    Jason Bobich
    Keymaster

    Hello,

    What you’re doing doesn’t quite make sense. I think you’re getting confused between what post formats are and custom post types are.

    You can’t do this:

    add_theme_support( 'post-formats', array( 'anmeldelse' ) );

    … because “anmeldelse” is not a WordPress post format: http://codex.wordpress.org/Post_Formats#Supported_Formats

    There’s nothing special about creating a custom post type with Alyeska that would be different than any other theme. In your child theme’s functions.php, you’d register it:

    http://codex.wordpress.org/Function_Reference/register_post_type

    And then you’d create a file to display it according to basic WordPress template hierarchy:

    http://codex.wordpress.org/Template_Hierarchy

    (i.e. you’d create a file in your Child theme called single-{your_post_type}.php)

    #4075
    iohannis
    Participant

    Thanks for the reply, Jason. My question then is whether to copy the single.php from the Alyeska parent theme – since it says don’t copy, I wanted to avoid that. But I guess I can copy the single.php file and the content.php template part, and simply edit the template part in the child theme…

    #4090
    Jason Bobich
    Keymaster

    You’re right; It is better not to copy single.php over to your Child theme if you don’t have to in order to avoid future conflicts with updates.

    No matter how you want to filter these template parts, you’ve got the filter “themeblvd_template_parts” you can use. Whether you want to use a post format or a custom post type, you can still filter to your needs.

    http://dev.themeblvd.com/tutorial/editable-content-files/#customize

    Ok, so what you’re going for is targeting a custom post type registered as “anmeldelse” and you also want to use a file called content-anmeldelse .php. Here’s one possible way you might go about it:

    function my_template_parts( $parts ) {
    	if( get_post_type() == 'anmeldelse' )
    		$parts['single'] = 'anmeldelse';
    	return $parts;
    }
    add_filter( 'themeblvd_template_parts', 'my_template_parts' );

    http://codex.wordpress.org/Conditional_Tags#A_Post_Type

Viewing 3 replies - 1 through 3 (of 3 total)
  • The forum ‘Alyeska Responsive WordPress Theme’ is closed to new topics and replies.