* Template name: My Custom Template
* Open the unordered list
if( !function_exists( 'my_custom_template_before_while' ) ) {
function my_custom_template_before_while( $template_name, $context, $query, $atts ) {
echo '<ul class="my-custom-list">';
add_action( 'wp_query_before_my_custom_template_while', 'my_custom_template_before_while', 10, 4 );
* Output the content for each post
if( !function_exists( 'my_custom_template_content' ) ) {
function my_custom_template_content( $template_name, $context, $query, $atts ) {
printf( '<li><a href="%s">%s</a></li>', get_the_permalink(), get_the_title() );
add_action( 'wp_query_my_custom_template_content', 'my_custom_template_content', 10, 4 );
* Close the unordered list
if( function_exists( 'my_custom_template_after_while' ) ) {
function my_custom_template_after_while( $template_name, $context, $query, $atts ) {
add_action( 'wp_query_after_my_custom_template_while', 'my_custom_template_after_while', 10, 4 );