Jump to content

When is content.php called in wordpress twentyfifteen theme?


colap

Recommended Posts

In index.php of that theme or other wordpress themes usually, unless they include other files or functions special for a theme.

 

get_template_part() is the function that includes other files into the template.

 

In twentyfifteen theme it's get_template_part( 'content', get_post_format() );

If get_post_format() returns "Standard" format, then will it be "content-get_post_format()" ?

Link to comment
Share on other sites

get_post_format() actually returns a true/false boolean.
 
Wordpress theme functions consider this as standard.
 
get_template_part('content',get_post_format());
would be
get_template_part('content',false);
 
Since get_template_part expects a string, you would leave it empty or add a string name there.
If you wanted to keep it the same throughout a theme could define format as standard with a check.

$format = get_post_format();//boolean true/false

//do a check for true or false and assign it a string
if ( false === $format ) {

	$format = 'standard';

}
get_template_part( 'content', $format );

 
The second function variable is optional, but if used the code above would look for content-standard.php, adding it to the content area.
So add a file named content-standard.php
 
 
If you want to assign get_template_part() with different strings, should use get_post_format_string()

get_post_format_string('standard');
 
And here is the function within wordpress post-formats.php for that to see your available options

function get_post_format_strings() {
            $strings = array(
                    'standard' => _x( 'Standard', 'Post format' ), // Special case. any value that evals to false will be considered standard
                    'aside'    => _x( 'Aside',    'Post format' ),
                    'chat'     => _x( 'Chat',     'Post format' ),
                    'gallery'  => _x( 'Gallery',  'Post format' ),
                    'link'     => _x( 'Link',     'Post format' ),
                    'image'    => _x( 'Image',    'Post format' ),
                    'quote'    => _x( 'Quote',    'Post format' ),
                    'status'   => _x( 'Status',   'Post format' ),
                    'video'    => _x( 'Video',    'Post format' ),
                    'audio'    => _x( 'Audio',    'Post format' ),
            );
            return $strings;
    }
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.