• I asked a few people on #wordpress, and no one seemed to think that there’s a solution, but I’m wondering if anyone has a suggestion on how to call the index.php without WP overriding and using home.php

    Basically I have a design I’m working on, and want the home page (home.php) to use a big footer and specific #posts on the page. I then want to be able to have a second version, that has a more “traditional” feel, with multiple posts and a right handed sidebar.

    When I try to load mysite.com/index.php, the home template is still being used.

    One suggestion I’ve gotten has been theme switching, which I’m not keen on, as well as my own work around, to create a master category, put all other cats in that, then create a category template like the traditional sidebar look I’m after.

    Any brainstorming, suggestions greatly welcomed.

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter Michael Bishop

    (@miklb)

    er, thought I had a solution, was wrong.

    Have you looked at wp-includes/template-loader.php yet?

    There is a hook there for do_action(‘template_redirect’);

    Then there’s the function get_query_template(‘filename’); in functions.php where it will look for filename.php as the template for that case.

    For solving all this, much comes down to the $wp_query object, which is defined in classes.php, and understanding how it would receive home.php compared to index.php.

    I’d like to understand everything in classes.php, but it’s a difficult read. For instance, I’d like to understand what this function is doing:
    function parse_query_vars() {
    $this->parse_query('');
    }

    although it doesn’t appear to be called anywhere.

    Found more info on the wp_query class and discovered the interesting read in classes.php is found at the bottom with the WP class.

    If you did a test plugin with a couple functions such as

    function is_custom_page () {
    global $wp_query;
    if ( $wp_query->query_vars['category_name'] == 'home' ) return true;
    }

    And for the action to add to template_redirect.php you called a function that did this:

    function get_custom_template () {
    if ( is_custom_page() && $template = get_query_template('customhome'); ) {
    include($template);
    exit;
    }

    And then added
    add_action(‘template_redirect’,’get_custom_template’);
    Then it would call customhome.php in your template folder if someone requested home, as in http://miklb.com/blog/home

    Thread Starter Michael Bishop

    (@miklb)

    Thanks for the replies. Sean from HeadZoo (via #wordpress) helped me with a quick and dirty plugin that I put into a functions.php file for a custom theme I’m working on, and he used the template_redirect. As I look into it closer, I’ll post back exactly what it is he did. But basically I’m adding a ?i=1 to the URL for the index.php, and the function then forces WP to load the index.php template, rather than the home.php template. Which was the goal.

    You could change the get_query_template('customhome'); line to get_query_template('index'); for that.

    And if ( $wp_query->query_vars['category_name'] == 'home' ) to if ( $wp_query->query_vars['category_name'] == 'index' )

    for the desired result at http://miklb.com/blog/index

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    As I look into it closer, I’ll post back exactly what it is he did. But basically I’m adding a ?i=1 to the URL for the index.php, and the function then forces WP to load the index.php template, rather than the home.php template. Which was the goal.

    That’s one way to do it, but there are others.

    The short of it is that home.php gets loaded because is_home() is set to true and home.php exists. is_home() gets set to true whenever it’s not an attachment, archive, single post, page, search, feed, trackback, 404, admin, or comments popup.

    The big question here is when, exactly, do you want home.php to be used, and when do you want index.php to be used? What separates the two? There’s a lot of hooks you could use to do it: template_redirect, parse_query, you could even use a filter on home_template… But you need some way to identify, for any given request, whether it’s supposed to use your template’s home.php or index.php.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    For instance, I’d like to understand what this function is doing:
    function parse_query_vars()

    It looks like it was designed to have it reparse the $query_vars and set all the is_whatever() variables again, however because of the way parse_query() works, it does a whole lot of nothing ($qv is a local variable that remains unset when the input to parse_query() is empty). It will reset a few variables there, but there doesn’t seem to be a lot of point to it, as written.

    Thread Starter Michael Bishop

    (@miklb)

    Like I said, I originally thought I could simply point to mysite.com/index.php to load the index.php template, not a home.php template. That didn’t work.

    So Sean wrote a function that allows me to append ?i=1 to the end of my link, ie, mysite.com/index.php/?i=1 and it loads the index template. (for my particular use, I changed “i” to something else)

    He used the template_redirect hook. I’m sure with more time, the concept could be elaborated on, but for what I needed, it works. It was very gracious of him to help out, I’m constantly amazed at the WP community.

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    Like I said, I originally thought I could simply point to mysite.com/index.php to load the index.php template, not a home.php template. That didn’t work.

    Do you want that to work? That’s what I’m asking here.

    If you want mysite.com to go to home.php but mysite.com/index.php to go to index.php (in your theme), then it can probably be done. It’s just a matter of determining if that’s the way you want it to be or not.

    I thought that the whole point of having both home and index pages was to use home as an entry or splash page when people came to the domain URL, and then start the blogging on the index page. So I tried to do that, and I have not been able to get the index page to come up at all.

    Now I know that I can achieve the effect that I want by making a separate index.html page for my splash page, and then linking to the blog index page from that.

    splash page http://www.domain.com/index.html
    blog start http://wordpressinstall.domain.com/index.php

    But then what was the point of putting both home and index pages in WordPress? It is all so confusing.

    Well, if you have your site at
    domain.com
    and the blog at
    subdomain.domain.com
    then you don’t need any trick, unless you set your blog to be displayed at domain.com.

    Well, yes, because my webhost allows FIVE WordPress installations on each domain, so I have

    domain.com
    Wordpressone.domain.com
    Wordpresstwo.domain.com
    Wordpressthree.domain.com
    Wordpressfour.domain.com
    Wordpressfive.domain.com

    And only one http://www.domain.com/index.html

    Mind you, I am not complaining. I think WordPress is the most fantastic thing since the wheel and sliced bread. I am using it as a retirement hobby to see what I can create. And it has a marvelous functionality.

    To someone like me who started using computers in the days of punch card readers for input, what you young folks are creating is a whole new world. I think it is wonderful.

    long since last reply here but i find myself in the imposibility to understand how can i use index.php insted of single.php for some categories and single.php for the rest of them?

    the thread started for this is at http://wordpress.org/support/topic/89493?replies=10. Can you please heva a look and suggest a solution?

    i would set the variable that holds the single.php as the template for single posts to index.php for the “some” categories and rewrite it with the initial value of “single.php” for the other categories.

    thanks.

    Otto2:

    If you want mysite.com to go to home.php but mysite.com/index.php to go to index.php (in your theme), then it can probably be done. It’s just a matter of determining if that’s the way you want it to be or not.

    Is this possible without editing core files? Because it’s exactly what I want…

    I needed to do the same thing and in WP 2.1 and later the solution is built in, you just need to work it a little. The solution was found here. http://codex.wordpress.org/Pages#Page_Templates

    1. I copied my home.php to a new name (homepage.php) and inserted the code to define it as a template_page.
      <?php
      /*
      Template Name: Homepage
      */
      ?>
    2. I created a new page in the wp-admin called “Homepage” and chose my new template_page (Homepage) as its template. Apart from the title I left this page empty in the wp-admin as all the content came from the template.
    3. In the wp-admin > options > reading I chose “front page displays: A static page and chose my new Homepage I just created
    4. Repeated this process by copying index.php and making a template called Posts out of it and assigning it to the static posts page in wp-admin > options > reading

    Everything is working great now as seen on http://www.sendusout.com

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Referencing both Home.php and index.php’ is closed to new replies.