WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#25558 closed enhancement (duplicate)

Smarter get_template_part() function

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

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 4 years ago.
diff patch

Download all attachments as: .zip

Change History (6)

#1 @helen
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Version trunk deleted

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

#2 @Horttcore
4 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 4 years ago by Horttcore (previous) (diff)

#3 @Horttcore
4 years ago

  • Resolution duplicate deleted
  • Status changed from closed to reopened

@Horttcore
4 years ago

diff patch

#4 @SergeyBiryukov
4 years ago

  • Milestone set to Awaiting Review
  • Severity changed from trivial to normal

#5 @SergeyBiryukov
4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from reopened to closed

Duplicate of #13691.

Note: See TracTickets for help on using tickets.