Think ahead of time about scaling, maximize the use of standard Wordpress solutions, do a WP theme yourself, take care of the layout maker's convenience, push up on mobility - and update the company's blog so that readers, editors and managers love it. We made it.
The Promopult company blog is already 9 years old. During this time, he went through several transformations. Sergey Glazov , the technologist of our blog and other important pieces in the Promopult system, talks about the latter.
This is no longer discussed, because it has become the norm: a fast and simple standard for a company's blog, person, personal, and in general, of any kind - WordPress. It is possible to argue, but the fact remains.
I want to talk about what I came up with in terms of organizing code, working with a WordPress blog and its support. This story is about the process, because the current state is the last point in this process and it seems that the current state is the most successful compared to all past iterations in the approaches to the organization.
Rarely when a developer creates and thinks everything from scratch. More often it turns out that already ( more often, even for a long time, with a separate story ) there is a project that needs to be supported. Redesign, edits, huge TK and requirements. And in the conditions of existing things, you need to somehow quickly navigate and solve problems.
I accepted the blog in 2016, when it already had a long history and not everything is as good as it should be.
The primary task was to add adaptability to the existing blog topic: to make mobile users adequately read posts and use the site β Mobile First was talked about and written more and more, and statistics showed that the blog was read from mobile.
In parallel with these works, a new design was drawn.
I, as a developer, worked in tandem with a designer, without a lot of intermediaries in the discussion, so the communication process was faster and more lively. The obvious fact, of course, but for some reason in many processes it is neglected. And it turns out that the designer is doing something badly out of touch with reality. Talk with your mouth and discuss all the points. Every participant in the process is interested in doing well and cool. But not everyone understands that the process is a connected chain, and if an individual contractor at his site of work misses something or does not do it - it will be difficult for the next people in the process.
In the course of working on the mobile version, I saw the disadvantages and weaknesses of the organization of the development process. I wanted to speed up and simplify everything.
There was a DEV-version of the blog with a separate test database. Work with files took place on a remote server, testing took place at a separate address that was not available in the outside world. After work, testing and the birth of some unit of meaning - she rolled out to the combat blog through an appeal to the admin. What he did was separate magic.
For a blog where something changes once a year is a great process. But with the new edition and its needs such a process would be a big pain.
All code lies in. git repositories. The combat version of the blog is the master
branch of this repository. All work with the code occurs through commits to the dev
file or other branches associated with individual large tasks.
After the task is done, a Pull Request (PR) and / or Merge Request (MR) is created with a set of edits. The meaning of MR b PR is the same, but in different services - a different name. We have GitLab , therefore - Merge Request.
When creating MR, a temporary address of the form -git--test.dev.blog.promopult.ru
available, which is available only by IP for live testing on a test environment.
The code in the created MR is reviewed and checked automatically (code linters, which check the syntax according to predefined rules) and manually (the vertical of power in the team, stares at everything with its naval bulging attentive eye of the tmilid). After the review is completed, the βMergeβ button is pressed from the browser's .git-repository interface and all changes appear on the air of the combat blog after a brief, obvious period of time.
Work plan for blog redesign:
Layout - a separate stage of work. For convenient work with styles (CSS), markup and JS, a set of plug-ins and modules was used in the project, which is assembled through the Gulp tasks described in the Start Project Template ( SPT ) collector.
Keywords that are used in the static blog theme collector: HTML, CSS, JS, Babel, Gulp, PostCSS, SCSS, Nunjucks.
Upon completion of the layout, the structure was as follows ( only the first level directories are indicated ):
βββ design # Design, layouts and all Appββ app / # project sources: individual modules Distββ dist / # Compiled version of the project (html-files) and all the statics Ulpββ gulpfile.js / # Gulp.js config Packageββ package.json # File-builder config: packages, scripts
Each individual visual semantic element on the page, for example, a post card ( /components/article_card/
), was a folder in which it was:
- markup file ( article_card.html
),
- style file ( article_card.scss
),
- JS file ( article_card.js
).
And each page was assembled from such separate component blocks. It is convenient to manipulate blocks, and any changes do not affect neighboring elements.
At the output, the collector created the dist
folder, which contained ready-made html-files of pages for visual viewing in the browser at the editing and approval stage, as well as one style sheet all themes and two JS files: one file ( app.js
) described the logic and behavior site, the second ( vendor.js
) contained all the libraries used for the site (jQuery, fotorama, magnific-popup and others).
Then all this needs to be turned into a WordPress theme and think through the file structure. So that you can conveniently work with a static layout and next to it lay a WP-theme.
The list of layouts that the designer has prepared. They are the same as the WordPress files of the blog:
home.php
file).single.php
post / post page ( single.php
).page.php
).subscribe.php
).404.php
).tag.php
).category.php
).search.php
).A workflow with this approach and separation into a static version and a WordPress version of a theme occurs as follows: if you need to correct something in the visual part, the edits are made in a static version and transferred to the theme after the test. If edits are needed in some non-visual part, then only WP-theme files are changed.
The folder with the blog theme is bsp
. It is located on the way in a folder with the themes of the blog itself:
Wββ wp-content / # Custom WordPress site files β βββ themes / # Site Themes β β βββ app / # Sources for a static theme β β β βββ gulpfile.js / # Gulp-tasks for assembly β β βββ dist / # Build a static theme β β β βββ assets / # Resources: JS, CSS and graphics β β βββ bsp / # WP-Theme Blog PromoPult β β β βββ assets / # Resources: JS, CSS and graphics, copying from `/ dist /` β β β βββ home.php #Blog home page and other files in the root of the topic
The place of the wordpress theme is obvious and predetermined by the file structure of WordPress itself.
There are no other topics in the themes directory - everything standard has been deleted. There is a myth about improving performance in this way, but we did not notice. This is done rather for order in the code. There is no need to store something that is not used and will definitely not be used.
Also in .git are all WP-plugins that are used. On our site it is Google XML Sitemaps, RSS for Yandex Turbo, RusToLat and WP-PostViews.
The static, rolled-up prototype of the blog pages and source files were moved to the blog theme directory: so that it was convenient to interact with the logical part of the template and with all that is responsible for the appearance and behavior of elements on the page.
A static version of the project build - with source codes and all dependencies in the first attempt to organize the structure - was placed in the themes directory.
That is, next to the main theme of bsp
, the /app
directory has been added, which contains the source code for the theme layout and the gulp-builder. But in this version there was one tricky moment: static files were generated in a separate directory, and for the changes to be in the WP theme, you had to copy static style files and scripts to the assets
folder inside the theme.
In the first weeks this was decided by a simple console script, which copied the collected files from a static theme into a WP-theme. Superfluous action leads to errors. Therefore, the option was only to correct the structure.
We have three important directories (all the way from the root):
/wp-content/themes/bsp
/app
/dist
And inside it are assets
with style files, graphics and JS.
You need to arrange everything in such a way that the statics of stylesheets and scripts are collected in the correct folder ( /wp-content/themes/bsp/assets
).
The new version of the structure was as follows:
Ulpββ gulpfile.js / # Gulp-tasks for building Wββ wp-content / # Custom WordPress site files Plug βββ plugins / # wp-plugins β βββ themes / # Site Themes β β βββ bsp / # PromoPult Blog Topic β β β βββ app / # Sources for a static theme β β β βββ assets / # Resources: JS, CSS, and graphics (autogeneration) β β β βββ home.php #Blog home page and other files in the root of the topic Wββ wp-admin / # WP files for admin panel Wββ wp-includes / # WP system files
At the root of the whole project are gulp-tasks - and executed from the root. The gulp-tasks configuration describes the structure that static files are collected from the wp-content/themes/bsp/app
directory in wp-content/themes/bsp/assets
without any additional actions like copying, etc.
WP-theme files remain unchanged and work proceeds according to the old scenario: editing in statics β transfer to WP-files. Statics CSS and JS is generated immediately in the folder with the theme and everything just works.
All this was about the process of work. Now, about how the blog itself is arranged.
The main strength of the blog - the team. Editor, authors, layout designers.
The big task is to make working with blog content convenient in the admin area. And taking into account the fact that the topic of our blog was made specifically for content tasks and editorial requests, the admin panel was updated accordingly.
Any work is important to control. The layout of the article is a standard, formalized process that can be easily represented as a check list.
The idea saw the guys from EmailSoldiers . We decided to apply it at home.
If any item is not marked - the system will warn before publication.
By clicking on the links, underlined links in the list item - we highlight a specific item.
The check list is compiled in the same order as the additional post settings in the admin panel.
Closely intertwined with the check list of the publication described above.
When developing a theme, I tried not to use plug-ins, but to make a simple and easy solution for the problems of the theme. Highlights:
Post settings section is implemented through meta boxes and custom fields in WordPress.
Through the meta-box added and checklist publication.
In templates, working with fields is simple: if a field is not empty and filled in, we retrieve the value and show it. For example, this is how a block reaction to a post is displayed:
<?php if (get_post_meta($post->ID, 'postreaction', true)) { ?> <div class="article_reaction"> <div class="label-reaction"><span><?php echo get_post_meta($post->ID, 'postreaction', true); ?></span></div> </div><!-- /.article_reaction --> <?php } ?>
An example of the output of the reaction on the post card:
There are some nice little things that maybe no one sees. But if someone noticed - well.
For example, the publication date of the post in the cards and in a separate post in our Cyrillic alphabet and can bend. For some reason, this is not in the WordPress box. If the publication date is in the current year, then the year is not shown here, if the year is different from the current one - the date is shown together with the publication year.
Post comments counter. Long argued that "0 comments" or "no comments" is very confusing. The solution is very simple: do not show the comment count at all, if there are less than one comment.
In general, we are working separately on the comment system and would like to talk about this in a separate big post. We make a simple and convenient commenting system with simple authorization through social networks.
Your own likes: commenting or sharing links in social networks is a long matter by the standards of the rate of content consumption, but clicking on the βlikeβ and making it clear that the article is cool is simple and fast. We made our simple likes and put the counter in the post card. And huskies arrive pretty quickly. And since they stand at the bottom of the article - it is also a signal that the text read.
Made a dark theme for your blog - now it is fashionable. Taking into account the modular structure (in fact, the site is a set of blocks that are somehow combined with each other) and the organization of styles turned out pretty quickly.
The topic has a minification code markup, CSS and JS. CSS and JS are compressed through gulp-tasks in the statics collector, but the markup minification is done via WordPress-hook WP_HTML_Compression
.
And in the comments in the markup, we added a promotional code for those who are interested in how the site is designed from the inside and who first goes to watch the source code:
Caching CSS and JS. So that the stylesheets and scripts are cached, but they are always relevant if we redo something, we use filemtime (). Many then use ?<?php echo time(); ?>
?<?php echo time(); ?>
. But this option loads the file and makes a request with each call.
It is better to use this trick:
<link rel="stylesheet" type="text/css" href="<?php echo get_template_directory_uri(); ?>/assets/styles/style.css?t=<?php echo filemtime(get_theme_file_path().'/assets/styles/style.css'); ?>" />
In this case, the files will be downloaded if they have been changed, and the date of the file change will be added to the query parameter.
Despite the possibility and desire in some cases to get by with our solution, we still use plugins. Our list is:
.git
at work. For 2019, of course, strange advice, but this advice can save someone from gray hair and reprimand when something goes wrong.Work on the blog continues - stay with us.
Source: https://habr.com/ru/post/457402/
All Articles