更改标签云中的字体大小 [英] change the font size in tag cloud

查看:219
本文介绍了更改标签云中的字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想减小标签云中的字体大小(至少对于点击次数超过一个的标签而言).我一直在查看CSS文件,但在标签云中找不到有关字体大小的任何信息.你知道在哪里改变吗? (链接是www.veda-vit.de,以防万一.)

I would like to reduce the font size in tag cloud (at least for tags with more than one hits). I was looking in css file, but couldn't find anything about font size in tag cloud. Do you know where to change? (The link is www.veda-vit.de, just in case it's needed.)

推荐答案

WordPress定义了配置标签云的默认参数.这些参数在此处在法典中定义.请注意,您可以指定最小和最大字体大小.默认情况下,它设置为22,单位为pt.

WordPress defines the default arguments that configure the Tag Cloud. These arguments are defined here in codex. Notice that you can specify the smallest and largest font size. By default, it's set at 22 with a unit of pt.

要更改此默认行为,您将需要注册对WordPress Core中提供的过滤器的回调.

To change this default behavior, you will want to register a callback to the filter provided in WordPress Core.

在此示例中,我同时更改了最小和最大字体大小.您将需要针对特定​​的实现对其进行调整:

In this example, I'm changing both the smallest and largest font sizes. You will need to adjust it for your specific implementation:

add_filter( 'widget_tag_cloud_args', 'change_tag_cloud_font_sizes');
/**
 * Change the Tag Cloud's Font Sizes.
 *
 * @since 1.0.0
 *
 * @param array $args
 *
 * @return array
 */
function change_tag_cloud_font_sizes( array $args ) {
    $args['smallest'] = '10';
    $args['largest'] = '18';

    return $args;
}

在哪里放置代码

很多人会告诉您将其添加到主题的functions.php文件中.我不是那些人中的一员.我教导并倡导模数主题和插件开发.这意味着主题的functions.php文件不应成为所有内容的收集点.

Where to Put the Code

A lot of people will tell you to add it to the theme's functions.php file. I'm not one of those people. I teach and advocate modular theme and plugin development. That means the theme's functions.php file should not be a collection point for everything.

话虽如此,您可以根据需要将以上代码添加到functions.php文件中.

With that said, you could add the above code to your functions.php file if you wish.

执行以下步骤:

  1. 打开主题的functions.php文件.
  2. 向下滚动到文件的最底端.
  3. 如果找到一个封闭的PHP标记元素,即?>,请将其删除.没必要.
  4. 将以上代码复制并粘贴到文件中(在文件底部).
  5. 保存文件.
  6. 如果它在服务器上,则通过SSH或SFTP进行传输.
  1. Open your theme's functions.php file.
  2. Scroll down to the very bottom of the file.
  3. If you find a closing PHP tag element, i.e. ?>, delete it. It's not necessary.
  4. Copy and paste the above code into the file (at the bottom of the file).
  5. Save the file.
  6. If it's on a server, then transfer it either by SSH or SFTP.

模块化方法

我主张使用模块化,方法是将功能和主题配置拆分为支持单一用途的独立文件.

Modular Approach

I advocate a modular approach, by splitting up functionality and theme configuration into separate, distinct files that support a single purpose.

在您的主题中,您应该使用一个名为libincludessrc的文件夹.您可以在此文件夹中放置自定义功能文件.

In your theme, you should a folder called lib, includes, or src. This folder is where you put custom functionality files.

在这些文件夹之一中,创建一个新文件,并将其命名为widgets.php.在此文件的第一行中添加以下代码:

Within one of those folders, create a new file and call it widgets.php. Within this file, add the following code at the first line:

<?php
/**
 * Widgets functionality
 *
 * @package     YourTheme
 * @since       1.0.0
 * @author      your name
 * @link        your URL
 * @license     GPL-2+
 */

然后在上面添加上面的代码.

Then add the above code below it.

现在,您需要加载该文件.打开主题的functions.php文件,导航到文件末尾,然后添加以下代码:

Now you need to load that file. Open up the theme's functions.php file, navigate to the end of the file, and then add the following code:

include_once( __DIR__ . '/lib/widgets.php' );

只需将lib替换为您将新文件放入的文件夹的名称即可.

Just replace the lib with the name of the folder you put the new file into.

字体大小由WordPress设置为嵌入式CSS.您可以使用上面的代码覆盖这些代码.不建议通过!important通过CSS强制使用.让WordPress来做它的事情,并按照上面所示设置最小和最大.

The font-size is set as an inline CSS by WordPress. You can override those using the above code. It's not recommended to force it via CSS with !important. Let WordPress do its thing and just set the min and max as shown above.

这篇关于更改标签云中的字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆