15158846557 在线咨询 在线咨询
15158846557 在线咨询
所在位置: 首页 > 营销资讯 > 网站运营 > 网站建设

网站建设

时间:2022-07-27 17:57:01 | 来源:网站运营

时间:2022-07-27 17:57:01 来源:网站运营

Convert an HTML Theme Manually

The advantage of this method is that you will get a perfect replica of your HTML site at the end. To some extent, you create a custom theme for your HTML website. It may sound terrifying for less experienced users, but it’s not as complicated as it seems.

The disadvantage of manually converting an HTML theme is that it requires basic coding skills. However, most operations can be reduced to copying and pasting. Follow the next steps to convert your site.

1.Create a Theme Folder

Open up your code editor of choice and chose a name for your WordPress theme. Create a folder on your computer hard drive and name it as the WordPress theme to develop and create five blank .txt files inside it. Name them as the following:

2.Copy + Paste CSS the Existing CSS

Open up the style.css file with your code editor, paste the following lines of code, and replace some theme details to match your theme information:

/*Theme Name: KeenTheme URI: https://keentodesign.com.auAuthor: Keen To Design TeamAuthor URI: https://www.keentodesign.com.auDescription:Custom theme for Keen To DesignVersion: 1.3Requires at least: 5.0Tested up to: 5.4Requires PHP: 7.0License: GNU General Public License v2 or laterLicense URI: http://www.gnu.org/licenses/gpl-2.0.htmlText Domain: keentodesignThis theme, like WordPress, is licensed under the GPL.Use it to make something cool, have fun, and share what you've learned with others.*/It’s good practice to fill in the header part of the style.css file with the required data. Some items are mandatory to get your theme approved in the WordPress repository. Here is what you have to fill in:

Copy the CSS file of your HTML theme, paste it in the style.css, save and close the file.

3. Separate Existing CSS

Your HTML theme includes the header, sidebar, and footer in the same file – index.html. Chop up the index.html to create a few WordPress-specific files. It’s about header.php, sidebar.php, and footer.php. Practically, we transform the HTML file into a few PHP files.

Let’s start with header.php. Select all the lines of code from the beginning until the first line of the content area of the index.html file. Before </head> tag, place this line of code:

<?php wp_head();?>sidebar.php is the next file. Go to index.html, copy everything between the <aside> tags and paste it in the sidebar.php. Next, copy everything from the end of the sidebar to the end of the file and paste it into the footer.php file.

4. Edit header.php

Search in header.php for this line of code:

<link rel=“stylesheet” href=“style.css”> Replace it with the following:

<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/style.css" type="text/css" media="all" />In non-developers’ language, you replace the way HTML calls the styling file with the way WordPress does.

5. Edit index.php

Open up index.php (it should be a blank file) and paste the following line of code:

<?php get_header(); ?> Next, paste the following snippet of code:

<?php if (have_posts()) : ?><?php while ( have_posts() ) : the_post(); ?> <article class=“<?php post_class(); ?>” id=“post-<?php the_ID(); ?>”> <h2 class=“entry-title”><?php the_title(); ?></h2> <?php if ( !is_page() ):?> <div class=“entry-meta”> <p>Post date <?php the_date();?>. Posted by <?php the_author();?></p> </div> <?php endif; ?> <div class=“entry-content”> <?php the_content(); ?> </div> <div class=“entry-meta”><?php if ( count( get_the_category() ) ) : ?> <span class=“category-links”> Posted under: <?php echo get_the_category_list( ‘, ‘ ); ?> </span> <?php endif; ?></div> </article><?php endwhile; ?><?php else : ?><?php endif; ?>This snippet represents the Loop, which PHP code uses to display posts. Skilled coders may edit the above sequence of code to exclude categories or style the layout. Save your work and close the file.

6. Upload the Theme

At this stage, you have to upload the theme into the wp-themes/content/ directory. Head to the WordPress admin dashboard and click on Appearance > Themes. It should display your theme – install and activate it.

Keep in mind that your new theme lacks a lot of WordPress features and customization options. It’s a basic theme, but a skilled coder will know how to make it more powerful. Check the next method if you aren’t confident in your skills or you don’t have money to hire a developer to tweak your theme.

Other Method- Use A Child Theme

There is a less laborious way to convert an HTML theme to a WordPress theme. The advantage of this method is that even non-coders can use it to convert an HTML template. The disadvantage is that you won’t achieve a perfect replica of your site. People who want their WordPress theme to resemble the initial HTML theme pixel for pixel may be disappointed. Still, coders work miracles and they may be able to tweak the WordPress theme to look 99% identical to your HTML theme. Here is the complete algorithm to follow:

Pick The Parent Theme

Look for a theme, theme framework, or starter theme that looks similar to your HTML theme design. It takes time, but the more similar they are, the less work you will need to put in. Install the theme on your WordPress setup. We will call this the parent theme. For learning purposes, I will use Twenty Fifteen as a parent theme (it’s the theme chosen in the WordPress Theme Handbook to create a child theme).

Create a Folder

Use an SFTP client to log in to your WordPress setup and create a new folder on the wp-content/themes directory. Name the folder the same as the parent theme name and add “-child”. Create two blank files within this folder – functions.php and style.css.

Edit style.css

Open style.css in your code editor and paste the following snippet:

/* Theme Name: Twenty Fifteen Child Theme URI: http://example.com/twenty-fifteen-child/ Description: Twenty Fifteen Child Theme Author: John Doe Author URI: http://example.com Template: twentyfifteen Version: 1.0.0 License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready Text Domain: twentyfifteenchild*/Replace the items descriptions to match your theme selection. Pay close attention to the Template item – put the name of the parent theme here. It won’t work unless you did it correctly. In non-coders’ language, this code introduces your theme and informs everyone that it’s a child theme.

Edit functions.php

Open functions.php and paste the following snippet:

<?phpfunction enqueue_parent_theme_styles() { $parent_style = ‘parent-style’; wp_enqueue_style( $parent_style, get_template_directory_uri() . ‘/style.css’ ); wp_enqueue_style( ‘child-style’, get_stylesheet_directory_uri() . ‘/style.css’, array( $parent_style ), wp_get_theme()->get(‘Version’) );}add_action( ‘wp_enqueue_scripts’, ‘enqueue_parent_theme_styles’ );By pasting this code, your child theme inherits the parent theme’s styling.

Activate the Child Theme

Go to your WordPress admin dashboard and activate the child theme.

Adjust the Site and Import Content

You have created the WordPress theme for your site, but it needs small adjustments and content import. The depth of the adjustments depends on your HTML theme design and the parent theme customization options. If you found a WordPress theme similar to your HTML theme, you are lucky. Otherwise, you have more customization work to do.

Next, you have to import the content. Use the Custom HTML Gutenberg block and paste the needed sequences of code from index.html. Another way is to create a new page from the WordPress dashboard and paste items from index.html step by step. You have full control over each item and the freedom to make improvements on the go.

Bonus: Two Alternatives

People without budget limitations may hire WordPress agencies to convert an HTML theme to a WordPress theme. It’s comfortable and hassle-free, but the price tag isn’t for every budget, especially for complex sites.

You know the saying that there is a plugin for every WordPress issue. Well, there is a plugin that considerably streamlines the conversion. HTML Import 2 is relatively simple to use and it has done good jobs in the past. However, it hasn’t been tested with the latest three major WordPress releases. As a result, it may not work for your site or conflict with other plugins. Also, this un-updated plugin is a vulnerability for your site security. Sadly, we didn’t find a plugin replacement for HTML Import 2. Did you find a plugin alternative? Please let us know by leaving a comment and we will update the post.

关键词:建设

74
73
25
news

版权所有© 亿企邦 1997-2025 保留一切法律许可权利。

为了最佳展示效果,本站不支持IE9及以下版本的浏览器,建议您使用谷歌Chrome浏览器。 点击下载Chrome浏览器
关闭