Support » Fixing WordPress » There’s More To Life Than INDEX.PHP

  • I’ve spent some time poring through the support forum and documentation to discover a way to link my WP entries to a different template than index.php. I mean, I LIKE index.php, it’s very pretty and never says mean thing about me, but sometimes a man wants his entries to load in a new template…a fresher template.
    Anyway, all I can find about this is several threads about how you are supposed to be able to link to new templates but can’t. Is this true? DOes anyone know a way to target a different template?
    I know I can alter specific static links in a page by changing the link tag’s href property, but I’m talking about the permalinks for blog entries, the one’s that show up when you call wp_get_archives().
    I’m dying to direct each blog category to it’s own template.
    Thanks in advance for any suggestions, advice or emotional support.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thanks for the advice. I’m not having a problem, though, with making or modifying templates. Modifying index.php isn’t a problem. Creating a brand new template for WP isn’t problem. Making WP apply that template to permalinks
    is a problem, because it won’t.
    Your idea of making a seperate stylesheet for different “pages”, using the same template is interesting, but unfortunately, wont work. My goal is to have each category get it’s own template, with it’s own static links and permanent content…not doable with CSS alone.

    I once did something vaguely similar where I had two different templates, both called index.php but in different subdirectories. To get the permalinks and stuff to point back to the same template, I did some simple but horrible hacking in:
    * get_category_link function in wp-includes/template-functions-category.php
    * get_permalink function in wp-includes/template-functions-link.php
    * get_month_link function in wp-includes/template-functions-link.php
    .. in order to make all the URLs relative (i.e. index.php?p=… or ?cat=… instead of…)
    I basically jus replaced
    $file = get_settings(‘home’) . ‘/’ . get_settings(‘blogfilename’);
    $file = get_settings(‘blogfilename’);
    in each function.
    I say horrible because it will make it harder to upgrade to a more recent version of WP, and I don’t know whether it would work with fancy URLs using .htaccess rewriting. Oh, and I didn’t change the calendar function because I don’t use a calendar on that site, but I imagine you could change it the same way.
    Well, it’s horrible but it works for me…

    I managed to do something similar to what you want, but with one template for categories and one for individual entries.
    I’m not using .htaccess as I couldn’t get it to work. Instead, in the permalink options, I set the first box to:
    and the second to:
    This gives me three templates – one for the home page, one for category listings and one for posts.
    Here’s the result (available but still a little work on the content):

    Wah this is weird… I guess if I could understand why this works, without .htaccess, I’d finally understand how WP permalinks work. Is all the /cat/year/month/day/post-number/ stuff passed to the template as a query string or something?

    This gives me three templates – one for the home page, one for category listings and one for posts.

    The problem here is that ONLY the homepage uses the original index.php now, any other link is passed through indiv.php. It’s a great solution if you just want a new template for individual posts. Unfortunately, I’m looking to make a template for each archive (category). Thanks, though. If all else fails, I’ll restructure the IA of the site and use this.

    two different templates, both called index.php but in different subdirectories

    eric, were all the function include files in both folders? In other words, to make your hack work, did you have two folders containing all the WP files, differently hacked with relative URLs?
    You idea seems plausible, and even extendable to use more than just two folders. The difficulty would be getting the category permalink in the first folder’s pages to point to the second folder’s pages…i.e., how to make the two different templates interact?

    I use a single installation of WP and each of the files mentioned only exist in the one directory where all the WP stuff resides.
    A simple way to link between cats might be to leave out the “wp_list_cats” tag from your menu, and instead define a link category called “Categories” and add a link (absolute URL) for each category. That way you could manage your cat links from within the WP backend. Of course it wouldn’t automatically create/delete/rename the link whenever you create/delete/rename a category. As I said, simple but horrible 🙂
    I should add that the purpose of my hack is completely different from what you are trying to do: to create a public area and a members area within the same blog (members index.php lives in password-protected directory).

    Really good ideas, eric. I don’t plan on changing my categories very often, and even if I do, having to manually change the absolute URLS in two or three files (actually, I could require_once() it in from a text file) is a small price to pay for the flexibility of using different templates. It’s certainly better than having to dump WP altogether and write my own CMS.
    Thanks a LOT for the help. I’ll give your trick a try this weekend and post back on how it works!

    The “blogfilename” is stored in database… and one uponce a time (in WP 1.1) it was possible to change this setting from admin pane !!!
    Where is this function now ???

    eryanv: interesting idea, I’m not sure I really get it though. Would you use .htaccess to make, say, blah.php an alias for index.php, and then define something like:
    $templatename = last part of $_SERVER[‘REQUEST_URI’]
    (everything after the last slash, I guess some PHP string processing function will do this)
    $file = get_settings(‘home’) . ‘/’ . $templatename
    That would be more flexible than my method because you could have template names other than index.php and wouldn’t need subdirectories. You would still need to hack functions in wp-includes, though. Am I anywhere near the right track?
    aris: I can’t find it either. But that still wouldn’t allow more than one template, right?

    Try this. I’ve found myself in the same situation…
    A 4-step guide to freeing yourself from the single index.php (I’m talking more than one index.php baby!)

    I thought you could use the read more include to point to a seperate file. Such as < ? php the_content("Read full article.","0","blah.php"); ? >

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘There’s More To Life Than INDEX.PHP’ is closed to new replies.