我想是我自己找到的。现在,我成功地添加了/photos 永久链接URL的端点,例如:
http://mywordpressite.com/projects/a-project/photos
然后是自定义模板,
photos.php 将加载并显示–可访问全局
$post 变量
有用链接:
在我的
functions.php 我为
single_template 和
query_vars 过滤器并添加了
photos 手持终端
add_rewrite_endpoint() 作用
// Permalink rewrites/add endpoints
add_filter( \'single_template\', \'project_attachments_template\' );
add_filter( \'query_vars\', \'add_query_vars\');
// You may need to go to wp-admin > Settings > Permalinks and
// save the changes in order to flush rewrite rules to activate.
add_rewrite_endpoint(\'photos\', EP_PERMALINK);
在文件的下面:
/**
* Add the \'photos\' query variable so Wordpress
* won\'t mangle it.
*/
function add_query_vars($vars){
$vars[] = "photos";
return $vars;
}
/**
* From http://codex.wordpress.org/Template_Hierarchy
*
* Adds a custom template to the query queue.
*/
function project_attachments_template($templates = ""){
global $wp_query;
// If the \'photos\' endpoint isn\'t appended to the URL,
// don\'t do anything and return
if(!isset( $wp_query->query[\'photos\'] ))
return $templates;
// .. otherwise, go ahead and add the \'photos.php\' template
// instead of \'single-{$type}.php\'.
if(!is_array($templates) && !empty($templates)) {
$templates = locate_template(array("photos.php", $templates),false);
}
elseif(empty($templates)) {
$templates = locate_template("photos.php",false);
}
else {
$new_template = locate_template(array("photos.php"));
if(!empty($new_template)) array_unshift($templates,$new_template);
}
return $templates;
}
请务必访问wp admin中的Permalink页面,以使更改生效。