Support » Themes and Templates » Pages AND Posts – want custom /home/ page & /blogs/ to list blogs

  • Hey there,

    I’m using the 1 install of WP as a CMS to run my site (Pages), and a blogging engine (Posts) at /blog/.

    What I’m after is a completely custom /home/ page, but every other page running off the same / similar template.

    Under Reading settings I have both static pages set – Home and Blog. Based on what I have read this appears to be correct.

    What I have trouble with is identifying the /home/ and /blog/ page in the PHP template.

    I originally wrote something like:

    <?php if ( is_home() || is_front_page() ) {
    		include(TEMPLATEPATH . '/myhome.php');
    	} else {
    		include(TEMPLATEPATH . '/body.php');
    	} ?>

    … where myhome.php is a unique template specifically for the /home/ page (I don’t want the headers, and have slightly different CSS), and body.php is for every other page. Works wonders.

    Until I click the /blog/ link.

    This seems to load some cross of the /myhome.php template without the appropriate stylesheets. Can’t quite work it out, but it’s definitely falling into the is_home() || is_front_page() if statement. This makes sense, I guess? – I’ve set /blog/ as the front page.

    I’m thinking there’s a correct combination of is_home(), is_front_page(), is_page(), etc. that should do this correctly for me.

    Anyone successfully written a theme like this, or got some template suggestions, with a custom /home/ page and the /blog/ page simply listing the blogs like it should, and all other ./pages displaying correctly too?

    Jason

Viewing 11 replies - 1 through 11 (of 11 total)
  • esmi

    (@esmi)

    Forum Moderator

    Your approach is logical but wrong for WordPress.
    Sstart by creating a custom page template, then apply that template to your chosen home Page.

    You are quite right. A custom page template for /home/ can be applied as such, and works quite well. Nice.

    Thanks.

    Still don’t have the blog working quite right but I have seen it so I must have tweaked my PHP a little too much. Will work on that.

    OK, this does work well but I can’t get the page at /blog/ and the subsequent Posts linked from this page to display in similar fashion to my Pages.

    Commands like list_pages don’t appear to work so well on the /blog/ and Post pages, and don’t list my CMS pages.

    So the above works:

    • custom template for /home/
    • every other page using the normal template

    But now – possibly down the wrong route? – I’m using is_page() logic to get the PHP template correct for the Pages / Posts.

    I have a <?php if (is_page()) { ?> statement with some PHP for all Pages, and then the <?php } else { ?> statement with different PHP which appears to kick in for /blog/ and any Blog Posts.

    This does seem to work. If I specify a template for the /blog/ it just doesn’t seem to work, possibly because the /blog/ page isn’t a normal page in this situation, but not entirely sure.

    Is this the correct way to go about getting the /blog/ listing and blog Posts looking slightly different to normal Pages?

    esmi

    (@esmi)

    Forum Moderator

    Commands like list_pages don’t appear to work so well

    list_pages in an old template tag that’s no longer supported. Try using wp_list_pages instead.

    I’m using is_page() logic to get the PHP template correct for the Pages / Posts.

    Wrong approach. If you’ve set your Home and Blog page using Admin/Settings/Reading/Front page displays, your Blog page will use the index.php file as its template.

    your Blog page will use the index.php file as its template.

    Blog will *always* use index.php? i.e. I should define my default Blog template within this file, then include my Pages template with {otherfile}.php as another template a reference that (With Home existing in yet another template).

    esmi

    (@esmi)

    Forum Moderator

    Your defined posts page will always use index.php. Not sure I understand the rest of your question.

    I’m finding that my blog page is ignoring my index.php and using home.php as a template. what would cause that?

    I had the same issue with my WordPress 3.0 install. I had home.php as a custom template and my default page pointed towards “home”. My posts page would never come up under /blog.

    I fixed it by moving home.php to myhome.php and renaming the template to MyHome. Then I re-saved the “home” page and it started working as expected. I wonder if home.php is a reserved filename.

    Anyways, I’m not sure if you need to rename the filename alone or also the name of the template within the file.

    Hope that helps and isn’t confusing.

    jimcasey

    (@jimcasey)

    I can confirm mcbutterbuns’ solution — I was running into the same issue. It appears that home.php is reserved for home page display (see Template Hierarchy) — I renamed home.php to home_template.php and /blog used the default template (page.php) again.

    chinmoy29

    (@chinmoy)

    First create 2 two page “Home” and “Blog” with blank content and create
    a page-home.php file. Copy the all content from index.php file / or write your own design code in this page-home.php file.

    Next, login into wp-admin and goto Reading/Settings section. Then choose the following options:

    Front page displays : activate A static page (select below)

    * Front page: Home
    * Posts page: Blog

    Thanks!!
    (if the issue is solve, mark is resolve)

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Pages AND Posts – want custom /home/ page & /blogs/ to list blogs’ is closed to new replies.