Forums

[resolved] new template file called home.php, any suggestions? (18 posts)

  1. herbiehysteria
    Member
    Posted 2 years ago #

    hi
    my problem is that i want my latest blog entry (just the date, title and category) added above the content on my static home page. my static homepage works fine but i have been researching and may need 2 create a seperate template file for the homepage to achieve this.

    can i just duplicate index.php and call it home.php?
    then add the php template tags to call the latest blog entry along with my static homepage content?

    i try to post to thios forum only as a last resory, after reading through he documentation and googling it, im still stuck.

  2. vtxyzzy
    Member
    Posted 2 years ago #

    You can certainly copy index.php (if that is what your static home page is using) and name it home.php. You will also need to add the Template Name comment at the top:

    <?php
    /*
    Template Name: home
    */
    ?>

    Then you can select this as the template for your front page and modify it as you said.

  3. herbiehysteria
    Member
    Posted 2 years ago #

    thanks for the reply vtxyzzy

    (if that is what your static home page is using)

    how do i confirm which template file is used to display the static homepage?

  4. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    it's actually most likely page.php, if it is just a static page

    http://codex.wordpress.org/Template_Hierarchy
    shows you how WP determines which template to use

    When first learning WP I would insert a line at the top of each of my templates with a comment
    <!-- page.php template --> for page.php, etc

    then when cruising around my site, I can view source code from within the browser and look for those comments......

  5. herbiehysteria
    Member
    Posted 2 years ago #

    RV, i thought as much, somebody else said as soon as you apply a static homepage, page.php is used to create it? however, does that mean page.php is used 2 create ALL my pages? i have about 20 pages.

    if i edit page.php to show the single last blog entry, it will show on ALL my pages. therefore, im thinking i have to create the home.php template file. this would have to have the call for the last blog entry, as well as the static home page. any further suggestions?

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    yes, page.php by default controls all your pages.

    you can create a template, with an exact copy of your page.php
    http://codex.wordpress.org/Pages#Page_Templates

    And call it absolutely anything you want (home.php is a special name.... http://codex.wordpress.org/Theme_Development#Theme_Template_Files_List )

    once you make the new template you can apply it to your static page. In the page editor there is a template dropdown that would let you select your newly created template

    The special templates only apply to the page(s) you apply them to, so you could make a template based on page.php, insert your new code and apply it to just the one page

  7. herbiehysteria
    Member
    Posted 2 years ago #

    RV,

    home.php is a special name....

    does that mean it will be assigned to the homepage, automatically?

    or should i create a new template called, say, homewithpost.php??

    PS: this is my existing page.php file, i can duplicate this as the new template but do i need the existing loop in there? also which code should i add to display the last blog entry with date and title?

    <?php
    /**
     * @package WordPress
     * @subpackage Default_Theme
     */
    
    get_header(); ?>
    
    	<div id="content-page">
    
    		<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    		<div class="post-page" id="post-<?php the_ID(); ?>">
    		<h2><?php the_title(); ?></h2>
    			<div class="entry">
    				<?php the_content('<p class="serif">Read the rest of this page &raquo;</p>'); ?>
    
    				<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
    			</div>
    		</div>
    		<?php endwhile; endif; ?>
    	<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
    	</div>
    <?php
     include
    (
    "sidebar2.php"
    )
    ; ?>
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    regards

  8. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    does that mean it will be assigned to the homepage, automatically?

    Honestly, I've never used it....but I believe that is the case....

    And as for your loop question....the loop you have there is what displays your static content, so you'll need to keep it....This stuff isn't my strength, so maybe someone else can help you with adding the latest post stuff

    Here's an example of someone displaying latest 3 posts, I'm sure it'll work for just one
    http://wordpress.org/support/topic/275600?replies=7

    Again, there are others here more qualified than me on this area

  9. herbiehysteria
    Member
    Posted 2 years ago #

    RV, thanks for the help
    ive duplicated page.php and called it hpage.php. when i go into admin> page> edit> the template options for the homepage don't include hpage. i only get a 'default template' and 'links' option. why wouldn't the new template show here?

  10. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    did you add the required header into the template?

    <?php
    /*
    Template Name: hpage
    */
    ?>
  11. webmasterguru
    Member
    Posted 2 years ago #

    also....did you add that file to wp-content -> themes -> default. I'm guessing that you are using the default template.

  12. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    I'm guessing that you are using the default template.

    Nope, he's got a theme he custom made

  13. herbiehysteria
    Member
    Posted 2 years ago #

    RV, yes it's done. ive added the code and it's working fine.
    check it out: http://www.artbyherbie.com

    im just going to add a title 'Latest Article' and the category/author info under the title link.

    thanks, as ever ur a superstar!

  14. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    Good stuff!

  15. herbiehysteria
    Member
    Posted 2 years ago #

    just one last thing RV!
    how can i get the title LATEST ARTICLE on the same line as the date?
    at the mo, the code looks like this and displays the title above the date.

    <div class="box<?php echo $counter--; ?>">
    
    <h3>LATEST ARTICLE</h3>
    <h3 class="date"><?php the_date(); ?></h3>
    <h3 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    </div>
  16. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    well....It's because they are each wrapped in separate h3 instances....You'll have to put them into one instance I think, then maybe use a span instead...?

    <h3 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><span class="date"><?php the_date(); ?></span></h3>

    its gonna be something like that.....I don't have access to any dev stuff at work, so I can't pin it down, you may have to experiment a little

  17. herbiehysteria
    Member
    Posted 2 years ago #

    sorted. thanks RV! i did try wrapping them in a <p> tag but it didnt work. <span> worked great!

  18. Rev. Voodoo
    Volunteer Moderator
    Posted 2 years ago #

    sweet!

Topic Closed

This topic has been closed to new replies.

About this Topic