Make WordPress Core

Opened 13 years ago

Closed 13 years ago

#25558 closed enhancement (duplicate)

Smarter get_template_part() function

Reported by: Horttcore Owned by:
Priority: normal Milestone:
Component: Template Version:
Severity: normal Keywords: 2nd-opinion has-patch
Cc: Focuses:

Description

The get_template_part() function could be much smarter if it takes any number or arguments.

function get_template_part() {
	$partials = array_filter( func_get_args() );
	do_action( "get_template_part_{$slug}", $args[0], $args[1], $args ); // $args[1] for compability

	$templates = array();
	if ( $partials )
		foreach( $partials as $partial ) {
			$templates[] = implode( '-', $partials ) . '.php';
			array_pop($partials);
		}

	locate_template($templates, true, false);
}

Attachments (1)

general-template.patch (923 bytes ) - added by Horttcore 13 years ago.
diff patch

Download all attachments as: .zip

Change History (6)

#1 @helen
13 years ago

  • Milestone Awaiting Review
  • Resolutionduplicate
  • Status newclosed
  • Version trunk

Duplicate of #21676. Also, oddly, your patch looks reversed.

#2 @Horttcore
13 years ago

Actually its not a duplicate, as I don't want to pass any variable to it to use it in the scope.
I want to add a smarter way to locate a template file.

get_template_part( 'content', 'page', get_the_ID );

The template stack would be

content-page-10.php
content-page.php
content.php
Last edited 13 years ago by Horttcore (previous) (diff)

#3 @Horttcore
13 years ago

  • Resolution duplicate
  • Status closedreopened

@Horttcore
13 years ago

diff patch

#4 @SergeyBiryukov
13 years ago

  • MilestoneAwaiting Review
  • Severity trivialnormal

#5 @SergeyBiryukov
13 years ago

  • Milestone Awaiting Review
  • Resolutionduplicate
  • Status reopenedclosed

Duplicate of #13691.

Note: See TracTickets for help on using tickets.