我正在使用下面的 getExcerpt() 函数来动态设置文本片段的长度。但是,我的 substr 方法目前基于字符数。我想将其转换为字数。我需要单独的函数还是有一个 PHP 方法可以用来代替 substr?
function getExcerpt()
{
//currently this is character count. Need to convert to word count
$my_excerptLength = 100;
$my_postExcerpt = strip_tags(
substr(
'This is the post excerpt hard coded for demo purposes',
0,
$my_excerptLength
)
);
return ": <em>".$my_postExcerpt." [...]</em>";}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试格式化我正在创建的文件,以便每个名称/值对都在它自己的行上
我确信这很简单,但我的.ini文件根本没有格式化换行符.我错过了什么?
function wpseTest()
{
$query = "SELECT option_name, option_value FROM wp_options where option_name like 'test|_%' escape '|' AND option_value > ''";
global $wpdb;
$matches = $wpdb->get_results($query);
$mySettings = '[settings]\r\n';
foreach ($matches as $result){
$mySettings .= $result->option_name;
$mySettings .= ' = ';
$mySettings .= $result->option_value;
$mySettings .= '\r\n';
}
$mySettingsFileLocation = WP_PLUGIN_DIR.'/test/settings-backup.ini';
$mySettingsFile = fopen($mySettingsFileLocation, 'w');
fwrite($mySettingsFile, $mySettings);
fclose($mySettingsFile);
}
Run Code Online (Sandbox Code Playgroud) 下面的代码尝试采用 WP_Widget_Categories 类并将其用作基于默认类别小部件的自定义类别小部件的基础。
但是,我没有得到任何输出,并且小部件没有显示在“可用小部件”列表中。我究竟做错了什么?
<?php
/*
Plugin Name: My Categories Widget
Version: 1.0
*/
class MY_Widget_Categories extends WP_Widget {
function MY_Widget_Categories() {
$widget_ops = array( 'classname' => 'widget_categories', 'description' => __( "A list or dropdown of categories" ) );
$this->WP_Widget('categories', __('Categories'), $widget_ops);
}
function widget( $args, $instance ) {
extract( $args );
$title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Categories' ) : $instance['title']);
$c = $instance['count'] ? '1' : '0';
$h = $instance['hierarchical'] ? '1' : '0';
$d = …Run Code Online (Sandbox Code Playgroud) 在下面的html片段中,我希望"main"div仅在标记中不存在"menu"div时才有背景图像.这可能吗?
<div class="header">
<div class="siteTitle">site title</div>
<div class="tagline">site tagline</div>
<div class='menu'></div>
</div>
<div class="main"></div>
Run Code Online (Sandbox Code Playgroud) 我见过一些在线漂亮的打印模块代码.有人知道将多维数组格式化为可读显示吗?
例如,翻译这个:
array(83){[0] => array(2){["name"] => string(11)"CE2 Options"["type"] => string(5)"title"} [1] => array(1){["type"] => string(4)"open"} [2] => array(5){["name"] => string(8)"Template"["desc"] = > string(638)"test description"["id"] => string(9)"my_theme"["type"] => string(14)"selectTemplate"["options"] => array(13){
进入这...
array(83) {
[0]=> array(2) { ["name"]=> string(11) "My Options" ["type"]=> string(5) "title" }
[1]=> array(1) { ["type"]=> string(4) "open" }
[2]=> array(5) {
["name"]=> string(8) "Template"
["desc"]=> string(638) "Test description"
["id"]=> string(9) "my_theme"
["type"]=> string(14) "selectTemplate"
["options"]=> array(13) {
[0]=> string(10) "test"
Run Code Online (Sandbox Code Playgroud) 我有一系列.txt文件,我正在for循环中读取.我在[widget_]格式的一些文本文件中放置了一个令牌
因此,文本文件的全部内容可能是[widget_search].另一个文本文件可能包含内容[widget_recent-posts].其他人可能只有html格式的文本而根本没有令牌.
在for循环中,我正在执行preg_match以查看文本文件是否与内容匹配我的标记模式的文件.如果匹配,我正在执行一些条件代码.
但是,当我运行跟踪测试以查看是否匹配时,我收到错误.
错误是:
警告:preg_match()[function.preg-match]:编译失败:缺少终止],用于C:\ xampplite\htdocs\test\wp-content\plugins\widget-test\widget-test.php中偏移量为8的字符类在227行
这是第227行的代码:
if (preg_match("/[widget_/i",$widget_text)) {//do something}
Run Code Online (Sandbox Code Playgroud) 我有一些内容包含表单中的标记字符串
$string_text = '[widget_abc]This is some text. This is some text, etc...';
Run Code Online (Sandbox Code Playgroud)
我想在第一个']'字符之后拉出所有文本
所以我在这个例子中寻找的返回值是:
This is some text. This is some text, etc...
Run Code Online (Sandbox Code Playgroud) 在此页面上> http://matchcoverguy.com/kimballs-ice-cream-1920s-tall-universal/
单击"Pin It"按钮时,出现的弹出窗口显示空白图像.虽然,我有一个开放的图表metatag:
<meta property="og:image" content="http://matchcoverguy.com/wp-content/uploads/Kimballs.jpg"/>
Run Code Online (Sandbox Code Playgroud)
我还能做些什么才能让Pin-it按钮拉出图像?
我有一个 .ini 文件,其内容为...
[template]
color1 = 000000
color2 = ff6100
color3 = ff6100
color4 = 000000
Run Code Online (Sandbox Code Playgroud)
一个包含以下内容的文件是从functions.php调用的,它传入2个值:
$myTheme,是正在寻找颜色的主题/模板的名称,$spot,是正在寻找的特定颜色编号(颜色 1-4)
$myTheme = $_REQUEST['theme'];
$spot = $_REQUEST['spot'];
$myColor = get_option($myTheme);
$path_to_ini = "styles/". $myTheme . "/template.ini";
if ($myColor == "") {
if($spot == 1){$myColor = [insert color1 value here];}
if($spot == 2){$myColor = [insert color2 value here];}
if($spot == 3){$myColor = [insert color3 value here];}
if($spot == 4){$myColor = [insert color4 value here];}
}
echo $myColor;
Run Code Online (Sandbox Code Playgroud)
我正在寻求有关如何解析 ini 文件的帮助,以使用 template.ini 文件中的适当颜色填充括号内的数据。
当我使用原理图(ng new --collection=@foo/schematics myproject)构建我的站点时,一切正常,除了一件事:
生成的 angular.json 文件在样式数组中只包含一个样式文件,我需要它包含多个自定义样式文件:
ng 新原理图构建后的当前 angular.json:
"build": {
"options": {
"styles: [
"src/styles.scss"
]
}
}
Run Code Online (Sandbox Code Playgroud)
期望:
"build": {
"options": {
"styles: [
"src/styles.scss",
"src/custom1.scss",
"src/custom2.scss"
]
}
}
Run Code Online (Sandbox Code Playgroud)
我如何告诉 angular 原理图例程我想要包含这些额外的样式表?