最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

themes - How to create a second index.php?

programmeradmin1浏览0评论

I need a duplicate of index.php, but slightly modified. I added a "vote it up" plugin. So, I want the user to select how to display posts - by new or by popular. I know what to add to second index.php, but how to create a second index.php, thats the problem.

I need a duplicate of index.php, but slightly modified. I added a "vote it up" plugin. So, I want the user to select how to display posts - by new or by popular. I know what to add to second index.php, but how to create a second index.php, thats the problem.

Share Improve this question edited Apr 6, 2012 at 17:42 Chip Bennett 55.1k8 gold badges91 silver badges170 bronze badges asked Aug 27, 2011 at 23:33 Domante StirbyteDomante Stirbyte 111 silver badge4 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 0

Elaborating on Rachel Baker's answer:

Copy the index.php file and name it something like popular.php. At the very top, paste the following:

<?php
/*
Template Name: Posts by Popular
*/
?>

Now, go in to the WordPress admin and create a new page, called something like "By Popular". On the right-hand side, select the "Posts by Popular" template where it says "Template" (screenshot). Publish the page, and when you view it you should see your new page.

Create a link to this page in the nav menu or wherever, and then your users will be able to access the new page.

You can create a new page, using a modified template file - and send users to that page if they choose to display posts "by popular"

When i do this kinds of modification i always use child theme Because its the easy way to doing it. And if i mess the child theme up i can just copy files form the main theme anytime.

If you never tried the child theme. This might be the right time for you. ;) Just make a child theme copy the index.php file form original theme and place it to the child theme directory and edit.

If the OP is asking about creating a secondary index.php using a different theme, then it's not so simple: WP loads theme-specific constants right at load time and won't have it any other way. The only way to temporarily force a different theme is to create a plugin that will override the 'stylesheet' and optionally 'template' options, like this:

if ($GLOBALS['USE_SECONDARY_THEME']) {
    add_filter('stylesheet',function() { return 'mytheme-secondary'; });
    add_filter('template',function() { return 'mytheme'; }); // if the secondary theme is a child of mytheme
}

And then, in index-secondary.php, do

$USE_SECONDARY_THEME=true;

right before the usual

require_once( $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-load.php' );

that should be in a WordPress index file.

发布评论

评论列表(0)

  1. 暂无评论