Php script for archiving files. The default look and feel of WordPress archives

It is clear that it is easier for template creators to use the standard functions and tags of WordPress templates to display the standard views of all pages of the site, but this creates a uniform appearance and a sense of transition to the same pages of the site.

I'll show you what we get as a result.

View of wordpress archives: category archive before change
Category archive with removed thumbnails and a link to learn more.

Important! Since this task is solved by changing the template code, before work we do (database + site files). In addition, we make two copies of the working template, one for editing, the second for restoring the wrong editing.

Changing the Look of WordPress Archives

To change the look of WordPress archives, you need to find, or rather, determine which file in your working template outputs archives. In most templates, all archives are displayed in a single file, it is called (archive.php).

I repeat, for safety, to lose the site, do not use the editor in the site's administrative panel, but edit the pre-made backup copies of the template files.

In a text editor (such as Notepad++), open the archive.php file and start editing. In the archive.php file (at the end of the file) we are looking for a function that displays the archive blog:

Name is the name of the file that is used to output the blog archives.

The first idea to complete the task is simple: we need to change the code of the file that outputs archives (content.php), namely, remove several functions from it, and thereby change the appearance of all site archives (categories, authors, dates, etc.).

But the question arises, if we change the code of the template file, it will return to its previous state after the first update of the template, we do not need this. Therefore, we will not edit the content.php file, but copy it and create our own file, under a different name, for example content-cat.php and edit it.

We are looking for a function in the file that displays thumbnails. The thumbnail output function will be at the top. Remove thumbnail output.

orand remove the line with 'Read More', 'template name'.

The created and edited content-cat.php file is saved and uploaded to the site directory in the working template folder. This file will appear in the site administration panel on the Appearance→Editor tab.

Let's move on to the second step. In the file that outputs archives (archive.php), change the name of the content file to content-cat .

We save and look at the result. If those are wrong, the system will show the error, the error file and the error line. To correct the error, we return the saved template backup files to their place and repeat everything again.

Advice. If you want to read more about template tags and standard WordPress features, check out this site: https://wp-kama.ru . This is not an ad or even a link, this site is clearer than the official WordPress site in the template tags and features section.

In the development of the theme

In my opinion, the topic of announcements on WordPress sites needs to be continued. In the next posts, I will talk about the topics: and.

WordPress Codex

Hidden text

the_post_thumbnail function

Function

the_post_thumbnail

Purpose

The_post_thumbnail function outputs the html code of the post thumbnail image, empty if there is no image.

Application

This template tag, the_post_thumbnail function, must be used inside

Usage

the_post_thumbnail(string|array $size = "post-thumbnail", string|array $attr = "")

Source

File: wp-includes/post-thumbnail-template.php

Function the_post_thumbnail($size = "post-thumbnail", $attr = "") ( echo get_the_post_thumbnail(null, $size, $attr); )

Options

$size (string/array)

The size of the thumbnail to get. It can be a string with conditional sizes: thumbnail, medium, large, full or an array of two elements (image width and height): array(60, 60).

Default: 'post-thumbnail', i.e. the size that is set for the current topic by the set_post_thumbnail_size() function

$attr (string/array)

An array of attributes to add to the resulting html img tag (alt is an alternative name).

Default:

Example

"title="_("permalink"), the_title_attribute("echo=0")); ?>"> !}get("layout", "imgwidth"), $SMTheme->get("layout", "imgheight")), array("class" => $SMTheme->get("layout","imgpos") . " featured_image")); if (!is_single())( ?>

Each site is a story that has a beginning and an end. But how to trace the stages of the development of the project, its life cycle? For these purposes, there is a special service called a web archive. In this article, we will talk about the presentation of such resources, their use and possibilities.

What is a web archive and why is it needed?

A web archive is a specialized site that is designed to collect information about various Internet resources. The robot saves a copy of projects in automatic and manual mode, everything depends only on the site and the data collection system.

At the moment, there are several dozen sites with similar mechanics and tasks. Some of them are considered private, others are non-commercial projects open to the public. Resources also differ from each other in the frequency of visits, the completeness of the information stored and the possibilities of using the received history.

As some experts point out, information flow storage pages are considered an important part of Web 2.0. That is, part of the ideology of the development of the Internet, which is in constant evolution. The collection mechanics are very mediocre, but there are no more advanced methods or analogues. Using the web archive, you can solve several problems: tracking information over time, restoring a lost site, searching for information.

How to use web archive?


As noted above, a web archive is a site that provides some kind of history search service. To use the project, you must:

  1. Go to a specialized resource (for example, web.archive.org).
  2. In a special field, enter information for the search. It can be a domain name or a keyword.
  3. Get relevant results. This will be one or more sites, each of which has a fixed crawl date.
  4. By clicking on the date, go to the appropriate resource and use the information for personal purposes.

We will talk about specialized sites for searching for historical fixing of projects later, so stay with us.

Projects providing site history


Today, there are several projects that provide services for finding saved copies. Here are some of them:

  1. The most popular and popular among users is web.archive.org. The presented site is considered the oldest on the Internet, the creation dates back to 1996. The service conducts automatic and manual data collection, and all information is hosted on huge foreign servers.
  2. Peeep.us is considered the second most popular site. The resource is very interesting, because it can be used to save a copy of the information flow, which is available only to you. Note that the project works with all domain names and expands the boundaries of using web archives. As for the completeness of the information, the presented site does not save pictures and frames. Since 2015, it has also been included in the list of banned drugs in Russia.
  3. A similar project described above is archive.is. The differences include the completeness of the collection of information, as well as the ability to save pages from social networks. Therefore, if you have lost a post or interesting information, you can search through the web archive.

Possibilities of using web archives

Now everyone knows what a web archive is, what sites provide services for saving copies of projects. But many still do not understand how to use the information presented. The possibilities of archival data are expressed as follows:

  1. Choosing a domain name. It's no secret that many webmasters use already upgraded domains. It should be understood that experienced users track not only target parameters, but also the history of previous use. Each network user wants to know what he/she is getting: whether there were any previous bans or sanctions, whether the project fell under the filters.
  2. Restoring a site from archives. Sometimes a disaster happens that threatens the existence of your own project. The lack of timely backups in the hosting profile and an accidental mistake can lead to tragedy. If this happens, do not be upset, because you can use the web archive. We will talk about the recovery process below.
  3. Search for unique content. Every day on the Internet, sites that are filled with content die. This happens with special constancy, because of which a huge flow of information is lost. Over time, such pages fall out of the index, and a resourceful webmaster can borrow information for a personal project. Of course, there is a search problem, but that's a secondary concern.

We have reviewed the main features that web archives provide, it's time to move on to a more detailed study of individual elements.

Restoring a website from a web archive

No one is immune from website problems. Most of them are solved using backups. But what if there is no saved copy on the hosting server? Use the web archive. For this you should:

  1. Go to a specialized resource, which we talked about earlier.
  2. Enter your own domain name in the search bar and open the project in a new window.
  3. Choose the most successful picture, which is located closer to the problematic date and has a full view.
  4. Fix internal links to direct. To do this, use the link "http://web.archive.org/web/any_serial_number_id_/site name".
  5. Copy lost information or design data to be used for recovery.

Note that the process is somewhat tedious, given the speed of the archive. Therefore, we recommend that owners of large web resources perform backups more often, which will save time and nerves.

We are looking for unique content for our own website


Some webmasters use an interesting way to get new, unwanted content. Every day, hundreds of sites go into oblivion, and information is lost along with them. To become a content owner, you need to do the following:

  1. Enter URL
    https://www.nic.ru/auction/forbuyer/download_list.shtml#buying into the search bar.
  2. On the domain name auction site, download files with the name ru.
  3. Open the received files using excel and start the selection according to the parameter of the availability of design information.
  4. Enter the projects found in the list on the web archive search page.
  5. Open a snapshot and access the information flow.

We recommend monitoring content for plagiarism, this will allow you to find really worthy texts. And that's all! Now everyone knows about the possibilities and methods of using the web archive. Use knowledge wisely and profitably.

When you need to quickly download the source of the site from the server, even a relatively fast SSH tunnel does not provide the required speed. And the wait is very, very long. And many hosting providers do not provide this access, but make them content with FTP, which is several times slower.

Personally for myself, I determined the way out. A small script is uploaded to the server and launched. After a while, we get an archive with all the sources. And one file, even using the ancient FTP, downloads much faster than a hundred small ones.

Previously on this blog the library zipArchive. However, then it was about unpacking the archive.

First, we need to find out if the server supports zipArchive. This popular library is installed on the vast majority of hostings.

The library is strictly limited by php and server parameters. Huge databases and banks of photos cannot be archived. Even the bases of the good old 1C program for accounting. It would seem that they should contain only textual data. But no.

I advise you to use the library only when archiving relatively small sites with a huge number of small files.

Check if the library is available

If (!extension_loaded("zip")) ( return false; )

If all is well, the script will continue its execution further.

A small offtopic, for such checks. Checks should be done this way, avoiding large structures with nested parentheses. This will make the code more atomic and easier to debug. Compare

If(a==b)( if(c==d)( if(e==f)( echo "All conditions met"; )else echo "e<>f"; )else echo "c<>d"; )else echo "a<>b;

and this code

If(a!=b) exit("a<>b); if(c!=d) exit("c<>d); if(e!=f) exit("e<>f); echo "All conditions met";

The code is nicer and does not grow into huge nested constructs.

Sorry for the offtopic, but I wanted to share this find.

Now let's create an object and an archive.

$zip = new ZipArchive(); if (!$zip->open($destination, ZIPARCHIVE::CREATE)) ( return false; )

where $destination is the full path to the archive. If the archive has already been created, the files will be added to it.

$zip->addEmptyDir(str_replace($source . "/", "", $file . "/"));

where $source is the full path to our category (which we originally archived), $file is the full path to the current folder. This is done so that the archive does not contain full paths, but only relative ones.

Adding a file works in a similar way, but you must first read it into a string.

$zip->addFromString(str_replace($source . "/", "", $file), file_get_contents($file));

At the end, you need to close the archive.

Return $zip->close();

How to run through all the files and subdirectories in a folder, I think it is not necessary to explain. Google something like Recursive traversal of folders in php

I got this option

Function Zip($source, $destination)( if (!extension_loaded("zip") || !file_exists($source)) ( return false; ) $zip = new ZipArchive(); if (!$zip->open( $destination, ZIPARCHIVE::CREATE)) ( return false; ) $source = str_replace("\\", "/", realpath($source)); if (is_dir($source) === true)( $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); foreach ($files as $file)( $file = str_replace("\\", "/", $file); // Ignore "." and ".." folders if(in_array(substr($file, strrpos($file, "/")+1), array(".", ".."))) continue; $file = realpath($file ); $file = str_replace("\\", "/", $file); if (is_dir($file) === true)( $zip->addEmptyDir(str_replace($source . "/", "" , $file . "/")); )else if (is_file($file) === true)( $zip->addFromString(str_replace($source . "/", "", $file), file_get_contents($ file)); ) ) )else if (is_file($source) === true)( $zip->addFromString(basename($source), file_get_contents($source)); ) return $zip->close(); )