We output archives of categories. Changing the appearance of WordPress archives


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

I’ll show you right away what we get as a result.

Type of WordPress archives: archive of categories before changes
Archive of sections with removed thumbnails and a link for more details.

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 incorrect editing.

Changing the appearance of WordPress archives

in order to change appearance WordPress archives, you need to find, or rather, determine which file in your working template displays the archives. In most templates, all archives are output in a single file, it is called (archive.php).

I repeat, for the safety of losing the site, we do not use the editor in the administrative panel of the site, but edit pre-made backups template files.

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

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

The first idea for completing the task is simple: we need to change the code of the file that outputs the archives (content.php), namely, remove several functions from it, and thereby change the appearance of all the site’s 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 function will be at the top. We remove the thumbnail output.

orand remove the line with ‘Read More’, ‘template name’.

We save the created and edited content-cat.php file and upload it to the site directory in the working template folder. This file will appear in the site's administrative panel on the Appearance→Editor tab.

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

We save and look at the result. If something is wrong, the system will show an error, an error file and an error line. To correct errors saved backup files We return the template to its place and repeat everything again.

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

In development of the topic

In my opinion, the topic of announcements on WordPress sites requires continuation. In the coming 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 html code Post thumbnail images are empty if there is no image.

Application

This template tag, the_post_thumbnail function, must be used internally

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 receive. 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’, that is, the size that is set for the current theme by the function set_post_thumbnail_size()

$attr (string/array)

An array of attributes to add to the received html tag img (alt - 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())( ?>

Archives can be very beneficial to your blog - they give your readers a detailed view of all your posts and when they were published. These archives record information whenever you add posts to your blog. By default, WordPress has standard ways to display archives. Over time, the list of archives grows, and when you then place such an archive in a sidebar or widget, it takes up a lot of space.

To add new features to your archive, use the plugin. With it, you can display the archive the way you like. There are many archive plugins available for WordPress, we have selected the 5 best free plugins.

1. Snazzy Archives

Snazzy Archives is one of the popular archive plugins for WordPress, which has great capabilities and provides a visualized way to display the archive. This visualization will make your archives interesting. You'll be able to try out different styles and special effects for your archive to help it match your blog's design.

  • Visual representation.
  • Lots of features.
  • Display HTML & CSS.
  • Caching functions.

2. Smart Archives Reloaded

Smart Archives Reloaded— allows you to group blog entries by year and month. Using this plugin, you can use navigation elements to make your archive more interesting. This plugin takes up very little space, it does not require many resources, which results in faster page loading, and with the help of the settings you can make your archive the way you want.

Key points and features:

  • Grouping archives by year and month.
  • Navigation elements.
  • Requires little space.
  • User settings.

3. Collapsing Archives

Collapsing Archives– a plugin that will help you save a lot of space by using a special function to make your archive collapsible. You can make your archive collapsible by year and month. This is really useful because if you want to display your archive in the sidebar, you can save a lot of useful space there.

Key points and features:

  • Collapsible archive function.
  • Collapsible archive by year and month.
  • Save space in the sidebar.
  • jQuery support.

4. Simple Yearly Archive

Simple Yearly Archive— displays the archive of your blog by year. With it, you can also limit the display of certain categories. There is support for multiple languages, allowing users who speak other languages ​​to benefit from this plugin.

Key points and features:

  • Displaying the archive by year.
  • Easy to use.
  • Multi-language support.
  • Limiting the display of certain categories.

5. Annual Archive

Annual Archive is a free archive plugin for WordPress that has enough features to customize your archive the way you like. Using the widget, you can display archives by day, week, month, year, as well as alpha archives. You can also display your archive anywhere using a shortcode.

This plugin has support for all languages.

Key points and features:

  • Lots of features.
  • Shortcode option.
  • Sidebar widget.
  • Supports all languages.

Conclusion

Once your site starts to grow and you continue to write blog posts, it eventually comes down to the publication archive pages. These pages can be built on the basis of classifiers, catalogs, custom publication types, and even dates. WordPress has built-in support for these archive pages, but it does have some drawbacks.

Let's explain how you can get the most out of using this tool and ensure that it actually adds value to your blog.

Default WordPress archive pages

WordPress supports automatic creation of archive pages. This frees you from having to create them manually. Unfortunately, these pages usually consist of a list of publications based on categories/classifiers/types of publications without any detailed explanation.

This means that your visitors will be stuck on a page with no explanation as to where they ended up. The chances of users finding exactly what they are looking for are incredibly low in this case, so they usually leave such pages almost immediately.

There is a simple solution to the problem - add some kind of “introduction” to them. A clear title can greatly help your visitors, but for the most important archive pages, it is recommended to add a description to better highlight the content that can be found on that archive page.

Before you start writing passionate descriptions, make sure they appear correctly on the page.

Adding Introductions

Categories, tags and user classifications

If you want to add an introduction to an archive of categories, tags, or custom classifications, you can easily create a custom template file instead of the default one.

For example, you can create a file ‘ category.php' for your theme and replace the default file with it.

For more information on how the template hierarchy works in WordPress, just take a look at the article before continuing.

To the newly created file ‘ category.php' add the following code above the WordPress loop:

if (! is_paged()) ( echo wpautop(term_description()); )

If you want to support shortcut commands, use code like this:

if (! is_paged()) ( echo wpautop(apply_filters("the_content", term_description())); )

The above code snippet takes the title and description that you added in the WordPress Backend for the categories and which are displayed on the category archive page. This method is also suitable for tag archives and custom classifications.

How to create an interesting and beautiful page for viewing the category archive? This question may be of interest to many, since by default archives in WordPress are displayed in the same form, which is determined by the theme used. How to change the archives page and make it attractive and different for different sections of the site? This is the question that interested me, and I seem to have found the answer to it.

As you know, there are pages of simply calendar archives by month, and there are pages of category archives. The difference is that in the first case, you are simply shown all the posts for the month, while in the archives of a category you will see posts only for a specific category. But such pages look impersonal and identical. How to diversify them? There is an easy way out. But first, a little about the design of your WordPress.

Every WordPress theme has a file called archive.php. At least almost any time. This file is built in such a way that you can display all options for your general archive of articles: by category name, by publication date, by month or year of publication, by author (if there are several). The category.php file can also be organized as a separate unit. In this case, it will display records from the archive for a specific category (heading).

Now we can consider the question of how to make the site display one version of the archives page for one category, and for another category it is somewhat different, for example, with a short announcement of a specific category? You know that when creating a new category in the site admin panel there is a field called “Description”. This is what the page for creating new categories looks like:

Almost all WordPress themes implement the display of its description on the category page if you add it to this field. This action both visually diversifies the page and improves the SEO indicators of this page. You can take advantage of this and slightly redesign our page for displaying category archives. But it also happens that description output is not supported. If you find that your WordPress theme does not support Category Description output, feel free to take the next step:

In the file archive.php (or category.php) write the following code:

This line may look a little different, for example like this:

This line does not display the category description, so it needs to be changed to the one given above. That is, in the first example, the function means approximately the following: If you have a completed category Description, then it must be displayed. Each section on the site is assigned its own identifier, as is each entry. And there is absolutely no need to install any plugin to find out this ID - it’s on the surface. If you simply hover over the name of a category in the admin panel in the “Categories” section, you will see below in the browser that the address where this category is located and its identifier are displayed. For example:

The screenshot shows that for the “News” category its ID is 1. After this, it would be stupid to use a special plugin that specifies the identifier - the Reveal IDs plugin. We just don't need him.

How to display categories - we have finally come to this issue. In the Description input window, which we talked about above, you can use not just text, but HTML code - this way your description will be perceived better by robots, and it will look nicer and clearer if, for example, you highlight some important words with tags or . But this is a standard technique. We need to make sure that all categories are displayed differently. To do this, you can add images for each category. Here you can’t do without a plugin called CategoryTinymce. You already know how to download and install it. I write about this in almost every article describing a plugin. For example, you can read about this in the article “”.

After installing the CategoryTinymce plugin, the window for editing categories and their descriptions will look like this:

Now you can not only add a description for each category, but also accompany it with your own image using the standard WordPress visual editor. And lastly, how to make your own page with a description and image for each category? You know how to find out the category ID. This is what will help us. We consider that the “Category Description” and image fields are filled in. Now copy the category.php file and rename it to the category-ID.php file, where ID is the identifier of the category for which you created the description.

If there is no archive.php file (which I warned about above), then copy the archive.php file and save it under the name of the category that you need. That is, use the category identifier in its name. That's it - now for each of your categories for which you have created such files with an identifier name, both a description and an image for the category will be displayed. Make your website more beautiful!







2024 gtavrl.ru.