简而言之:不要使用single.php
. 如果你只有index.php
, 因为WP找不到任何其他模板来显示内容,所以所有帖子都使用此模板显示。
您的人类语言问题:
如果url为www.youpiemonday.com
, 加载frontpage(index.php、home.php或其他内容)
如果url为www.youpiemonday.com
使用参数,则显示参数内的单个帖子single.php
.
WordPress会这么做,因为youpiemonday.com/singlepost/
将由WP(内部)转换为www.youpiemonday.com/?p=123
(其中123
是的帖子IDsinglepost
)
所以你要做的是:
每次有人打电话www.youpiemonday.com
, 呈现frontpage(index.php,home.php,…)投资组合中没有一个帖子开放。But 如果url(/singlepost/)中有参数,则呈现frontpageand 打开单个帖子(如果可用)。
删除或重命名您的单曲。php强制WP使用索引。php的主题来显示各种帖子。要触发单击,可以在函数中添加开关。php
add_action( \'wp_head\', \'trigger_click_on_single_post\' );
function trigger_click_on_single_post(){
$js_template = \'
<script type="text/javascript">
jQuery( document ).ready(
function( $ ){
// create the js to trigger the link here
LinktoRef = $(".ProjectWrap" ).find( "a" ).href; // the href in the thumbnail
if ( "{{link_to_click}}" === LinktoRef ){
find( "a" ).trigger( "click" );
}
}
);
</script>
\';
if( is_single() ){
global $post;
$replace = get_permalink(); // create the propper url here
$js_output = str_replace( \'{{link_to_click}}\', $replace, $js_template );
echo $js_output;
}
}
PS:我不知道为什么,但是WPSE上的代码格式不喜欢heredoc语法。因此,代码块中有一个小小的中断。