wordpress显示摘要_在WordPress中突出显示php源代码

news/2024/7/24 8:47:50 标签: php, python, java, wordpress, laravel
<a class=wordpress显示摘要" width="403px" height="256px" style="outline: none;" />

wordpress显示摘要

The source code highlighting was probably the first feature I was missing in WordPress. I briefly googled my options and decided it would be quicker to add the missing feature myself, since it looked pretty straightforward.

突出显示源代码可能是我在WordPress中缺少的第一个功能。 我简短地搜索了我的选项,并决定自己添加缺少的功能会更快,因为它看起来非常简单。

So what I did: 1. I added a hilite() function in functions-formatting.php <?php

所以我做了什么:1.我在functions-formatting.php <?php添加了hilite()函数

function hilite($text)

函数hilite ( $ text )

{

{

    $text = str_replace('<? php', '<?php', $text);

$ text = str_replace ( '<?php' '<?php' $ text );

    return preg_replace_callback(

返回preg_replace_callback (

             "'<\?php.*?\?>'si",

“'<\?php。*?\?>'si”

             create_function(

create_function (

                 '$matches',

'$ matches'

                 'return highlight_string($matches[0], true); '

'return Highlight_string($ matches [0],true); '

             ),

),

             $text);

$ text );

}

}

?>

?>

The first line of the function is pretty curious, I agree. I needed it because I noticed that WP is adding a space between < and ? before saving to the database.

我同意,函数的第一行非常好奇。 我需要它,因为我注意到WP在<?之间添加了一个空格? 保存到数据库之前。

2. I added call to the new function in default-filters.php

2.我在default-filters.php中添加了对新函数的调用

add_filter('the_content', 'hilite');

add_filter('the_content', 'hilite');

... just before this line

...就在这行之前

add_filter('the_content', 'wptexturize');

add_filter('the_content', 'wptexturize');

And it worked! Only that the highlighting itself for some reason is using the HTML font tag (God forbid!), but I believe that's server setup.

而且有效! 出于某种原因,仅突出显示自身是使用HTML字体标签(上帝禁止!),但我认为这是服务器设置。

Edit: I added the filter to one more place in default-filters.php, in order to highlight source code when listing excerpts, for example category listing on an archive listing. So default-filters.php looks more like: add_filter('the_content', 'hilite'); add_filter('the_content', 'wptexturize'); add_filter('the_excerpt', 'hilite'); add_filter('the_excerpt', 'wptexturize');

编辑:我将过滤器添加到default-filters.php的另一个位置,以便在列出摘录时突出显示源代码,例如在归档列表中列出类别。 所以default- add_filter('the_content', 'hilite'); add_filter('the_content', 'wptexturize'); add_filter('the_excerpt', 'hilite'); add_filter('the_excerpt', 'wptexturize');看起来更像是: add_filter('the_content', 'hilite'); add_filter('the_content', 'wptexturize'); add_filter('the_excerpt', 'hilite'); add_filter('the_excerpt', 'wptexturize'); add_filter('the_content', 'hilite'); add_filter('the_content', 'wptexturize'); add_filter('the_excerpt', 'hilite'); add_filter('the_excerpt', 'wptexturize');

Tell your friends about this post on Facebook and Twitter

在Facebook和Twitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/highlighting-php-source-code/

wordpress显示摘要


http://www.niftyadmin.cn/n/1306942.html

相关文章

Python logging日志模块的使用

在实际的开发过程中&#xff0c;为了方便调试程序&#xff0c;记录系统的运行状态及错误等&#xff0c;及时发现系统的问题并快速定位问题&#xff0c;通常会使用日志。下面来介绍下在Python项目中如何使用日志。 Python提供了一个用于记录日志的标准库模块logging&#xff0c…

进入论坛出现403

1、今天登陆论坛&#xff0c;出现以下问题 2、论坛自己回复不能超过三次

dojo拼接成CSV格式字符串

var student "学号,姓名,年龄\n"; for(var i 0;i<resp.items.length;i) { student resp.items[i].id "," resp.items[i].name "," resp.items[i].age "\n"; } console.info(student);

qt 加载样式表_何时真正加载样式表?

qt 加载样式表Often we want to load a CSS file on-demand by inserting a link node. And we want to know when the file finished loading in order to call a callback function for example. 通常&#xff0c;我们想通过插入link节点来按需加载CSS文件。 而且我们想知道…

dojo之dojox/data/CsvStore初始化

dojo之dojox/data/CsvStore初始化 1、var csvStore new dojox.data.CsvStore({url:"student.csv"}); 2、var csvStore new dojox.data.CsvStore({url:"http://localhost:8080/student.csv"}); 3、var csvStore new dojox.data.CsvStore({identifier:&qu…

dojo省份地市级联之地市封装类(二)

dojo省份地市级联之地市封装类 City.java: /*** 地市封装类*/ package com.you.model;import java.io.Serializable;/*** author YHD**/ public class City implements Serializable {/*** */private static final long serialVersionUID 1L;/*** ID*/private String id;/**…

以太网帧有效载荷_减少有效载荷:压缩,缩小,204秒

以太网帧有效载荷2010 update: Lo, the Web Performance Advent Calendar hath moved 2010年更新&#xff1a; Lo&#xff0c; Web Performance Advent Calendar已移动 Dec 11 This post is part of the 2009 performance advent calendar experiment. Stay tuned for the next…

dojo省份地市级联之省份Dao接口类(三)

dojo省份地市级联之省份Dao接口类 ProvinceDao.java&#xff1a; /*** 省份-Dao*/ package com.you.dao;import java.util.List;import com.you.model.Province;/*** author YHD* see* date 2014-02-14*/ public interface ProvinceDao {public List<Province> findProv…