Skip to main content

Create Wordpress page template

When creating a new page in Wordpress, we usually have a choice for the page template. It's call Default template. However, we sometimes need to make a new page with a new appearance. Then another page template is needed. Instead of downloading a shared page template from internet, we can create a new page template by below instructions.




[caption id="attachment_504" align="alignnone" width="289"]Wordpress page template 1 Only have default template[/caption]

  • Create template file: 

    • Go to your website file manager and open your current theme directory: /wp-content/themes/your_current_theme_name/

    • Create a new file like your_new_template.php contains below codes with Your new template is your new template name:




[html]<?php
/*
Template Name: Your new template
*/
?>[/html]

  • Before building contents for new template, you should know the template tags. They will be used to display your template contents dynamically. Some common template tags are:

    • get_header():  display header part by including header.php file from your current theme directory;

    • the_content(): display the contents of current page;

    • get_sidebar(): display siderbar part by including sidebar.php file from your current theme directory;

    • get_footer(): display footer part by including footer.php file from your current theme directory;

    • And more tags at Wordpress Codex.



  • Coding template contents: using the template tags, we can simply build the template contents. We have an example for full width layout template here.


[html]<php get_header(); ?>
<div id="content" class="content">
<div class="post">
<div class="entrytext">
<?php the_content(); ?>
</div>
</div>
</div>
<?php get_footer(); ?>[/html]


That's all. After creating new template, you can now use it for new appearance page.



[caption id="attachment_505" align="alignnone" width="288"]Wordpress page template 2 Have option to choose another template[/caption]


Wish succeed!

Comments

  1. می‌گه: :چجوری باید تعداد برترین مطالب رو زیاد کنم ۳ تا فقط میاره !کد زیر رو در فایل lsidebar.php پیدا کنید و به جای ۱۵ هر عددی که خواستید بذارید$result = $wpdb->get_results( SELECTconemmt_count,ID,post_title FROM $wpdb->posts ORDER BY conemmt_countDESC LIMIT 0 , 15 );

    ReplyDelete

Post a Comment

Popular posts from this blog

Fix network printer error 0x0000709

When printing in the network, sometimes you see the error "Operation could not be completed (error 0x00000709). Double click the printer name and make sure that the printer is connected to the network".  Here we show how to fix the error: Open Windows Control Panel Open Credential Manager Choose Windows Credentials Click Add a Windows credential Internet or network address: input the computer name which share the printer User name: input "guest" Password: leave it blank Then click OK and reconnect the shared printer Do not need: uninstall Windows updates; change Windows registry... This maybe applied for error: 0x00000005, 0x0000011b... Watch the step by step video on here: