• Resolved Johnny Bravo

    (@herbiehysteria)


    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.

Viewing 15 replies - 1 through 15 (of 17 total)
  • 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.

    Thread Starter Johnny Bravo

    (@herbiehysteria)

    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?

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

    https://codex.www.ads-software.com/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……

    Thread Starter Johnny Bravo

    (@herbiehysteria)

    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?

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

    you can create a template, with an exact copy of your page.php
    https://codex.www.ads-software.com/Pages#Page_Templates

    And call it absolutely anything you want (home.php is a special name…. https://codex.www.ads-software.com/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

    Thread Starter Johnny Bravo

    (@herbiehysteria)

    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

    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
    https://www.ads-software.com/support/topic/275600?replies=7

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

    Thread Starter Johnny Bravo

    (@herbiehysteria)

    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?

    did you add the required header into the template?

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

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

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

    Nope, he’s got a theme he custom made

    Thread Starter Johnny Bravo

    (@herbiehysteria)

    RV, yes it’s done. ive added the code and it’s working fine.
    check it out: https://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!

    Good stuff!

    Thread Starter Johnny Bravo

    (@herbiehysteria)

    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>

    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

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘new template file called home.php, any suggestions?’ is closed to new replies.