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.
4 Answers
Reset to default 0Elaborating 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.