我在tinyMCE编辑器中有短代码,括在括号中,如下所示:
[my_shortcode]some text that gets parsed by my shortcode function[/my_shortcode]
Run Code Online (Sandbox Code Playgroud)
是否可以将运行时样式css应用于tinyMCE编辑器内容,以便括号中的任何元素(在我的短代码列表中*)获得特殊的css处理以使它们脱颖而出?
我们的想法是,短代码目前没有特殊的颜色或格式,以区别于任何周围的文本,除非它们更突出,否则很难使用它们.
我的短代码列表(示例):
[my_shortcode],[my_shortcode_2],[my_shortcode_3]
Run Code Online (Sandbox Code Playgroud)
更新:我将采取我可以得到的这个,但理想情况下,我只想将样式应用于括号,而不是括号缠绕的文本.所以我只想将运行时css样式应用于短代码括号:例如[my_shortcode]和[/ my_shortcode],并保留它们单独包含的文本.
有没有办法我们可以为已经创建的小部件分配一个短代码,然后再使用它
在我们的特定帖子和页面中的短代码,以显示小部件而不是琐碎的方法
在侧边栏中显示小部件?我用谷歌搜索这个东西没找到任何相对的东西.
任何建议都会受到欢迎!
我正在编写一个使用短代码的简单WordPress插件.我希望包含短<meta>代码的页面具有特定标记.这可能吗?如果是这样,有没有一种优雅的方式来做到这一点?
我知道我可以<meta>使用wp_head钩子添加标签,但我希望元标记内容与插件生成的字符串匹配.我可以将所有代码移动到标题中,但后来我不确定如何从短代码中引用它.换句话说,当我<head>使用过滤器声明一个变量时,它不能用我用短代码调用的类方法.
有任何想法吗?
更新:
提出了一个很好的解决方案,其中短代码的处理函数将操作添加到wp_head钩子:
add_shortcode('fakeshortcode', 'fakeshortcode_handler');
function fakeshortcode_handler() {
function add_meta_tags() {
//echo stuff here that will go in the head
}
add_action('wp_head', 'add_meta_tags');
}
Run Code Online (Sandbox Code Playgroud)
这是膨胀,但问题是wp_head在解码短代码之前发生并添加动作(所以没有任何东西被添加到头部,代码高于ALONE).为了使它工作,我在这篇文章中借用了解决方案.它基本上是一个"向前看"到帖子的功能,看看是否有任何短代码.如果是,那么IT增加了add_action('wp_head'....
编辑:我删除了关于如何传递变量的后续问题.这是一个新的问题在这里.
我知道这可能是一个回归问题.所以我把内容分开了,一个在一个函数中调用thelist,另一个是返回它的实际函数.代码遵循这个问题.
实际的短代码有效,除了内容出现在其他内容之前的顶部.我认为now_include_post返回会修复它,但事实并非如此.有人可以帮忙吗?
function thelist() {
if (have_posts()) : while (have_posts()) : the_post();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class('thumb'); ?>>
<a href="<?php the_permalink() ?>" class="thumb-link">
<?php
if (!post_password_required()) {
if (has_post_thumbnail()) {
the_post_thumbnail();
}
} else {
?>
<img src="<?php bloginfo('template_url') ?>/img/locked.png" />
<?php } ?>
</a>
<h2>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a>
</h2>
</div>
<?php /* end post */ ?>
<?php
endwhile;
endif;
wp_reset_query();
}
?>
<?php …Run Code Online (Sandbox Code Playgroud) 我用这段代码制作了一个菜单项.菜单项显示但短代码输出不存在.有什么我可以添加或不同的方法来做到这一点.我也希望这可能有所帮助.
add_filter('wp_nav_items', 'do_shortcode', 7);
Run Code Online (Sandbox Code Playgroud)
或者也许有人知道这是不可能的,可以告诉我.
/* Nav Menu */
function add_profile_link_to_nav(){
if ( is_user_logged_in() ) { ?>
<ul>
<li class="menu-item"id="one"> <a href="http://example.com/members/">All Members</a>
<ul class="sub-menu">
<li class="menu-item"><?php echo custom_execute_shortcode(); ?> </li>
</ul>
</li>
</ul> <!--end menu--->
<?php }
}
add_action( "wp_nav_items","add_profile_link_to_nav" );
function custom_execute_shortcode() {
$myfunction= '[my shortcode"]';
$myfunction_parsed = do_shortcode($myfunction);
return $myfunction_parsed;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我想创建自己的短代码
在文中我可以把短代码例如:
人很好,[gal~路线~100~100],人们都很好,[ga2l~route2~150~150]
在这个表达式中你可以看到[]标签中的短代码,我希望显示没有这个短代码的文本并将其替换为库(使用php include并从短代码中读取路径库)
我认为使用这种方法,你可以看到,但它们都不适合我,但是这里的人可以告诉我一些事情或给我任何可以帮助我的想法
<?php
$art_sh_exp=explode("][",html_entity_decode($articulos[descripcion],ENT_QUOTES));
for ($i=0;$i<count($art_sh_exp);$i++) {
$a=array("[","]"); $b=array("","");
$exp=explode("~",str_replace ($a,$b,$art_sh_exp[$i]));
for ($x=0;$x<count($exp);$x++) { print
"".$exp[1]."-".$exp[2]."-".$exp[3]."-<br>"; }
} ?>
Run Code Online (Sandbox Code Playgroud)
谢谢
我有一个自定义帖子类型的"工作人员".我需要通过页面上的姓氏按字母顺序显示工作人员.我知道一个解决方法是使用自定义元框并将名字和姓氏分成两个字段,但我试图避免这样做,因为它看起来非常hackish并且不像使用title字段那样干净.
我有一个短代码工作,将显示自定义的帖子类型与请求的工作人员"类型"分类属性.这是一个例子:
[staff type="local"]
Run Code Online (Sandbox Code Playgroud)
我不能只是假设这是我想要的标题中的第二个单词,因为一些工作人员是夫妻,并且他们的名字将被列为:"Bob and Cindy Smith".
这是我到目前为止的短代码.
function get_staff($atts) {
extract( shortcode_atts( array( 'type' => 'international' ), $atts ) );
$loop = new WP_Query(
array (
'post_type' => 'staff',
'orderby' => 'title',
'staff-type' => $type
)
);
if ($loop->have_posts()) {
$output = '<div class="staff">';
while($loop->have_posts()){
$loop->the_post();
$meta = get_post_meta(get_the_id());
$output .= '
<div class="staff" style="float: left; display: block; border: 1px solid #CCC; margin: 10px; padding: 12px; background-color: #eee;">
<a href="' . get_permalink() . '">
' . get_the_post_thumbnail($post->ID, 'thumbnail') …Run Code Online (Sandbox Code Playgroud) 我知道这一定要问过一百次,但我一直在尝试一些我能找到的解决方案,但似乎都没有.
我有一个shortcode包装内容:
[important_note]Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Nam vel velit at ex congue aliquet.[/important_note]
Run Code Online (Sandbox Code Playgroud)
我正在使用以下短代码功能functions.php:
function important_note( $atts, $content = null ) {
return '<div class="imp-note">'.$content.'</div>';
}
add_shortcode("important_note", "important_note");
Run Code Online (Sandbox Code Playgroud)
这是生成的html代码:
<div class="imp-note">
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
<p></p>
<p>Nam vel velit at ex congue aliquet.</p>
</div>
Run Code Online (Sandbox Code Playgroud)
主要问题是<p>我一直试图使用这里提到的解决方案来解决这个问题:通过php functon和Github 从wordpress短代码中删除空<p>标签然而这似乎解决了<p>包装shortcode不是内容的问题shortcode.
第一行没有任何<p>包装也有点奇怪,这让我觉得我应该在短代码函数中添加代码?
在此先感谢您的帮助.
UPDATE
好的,所以这段代码看起来像是诀窍:
remove_filter( 'the_content', 'wpautop' …Run Code Online (Sandbox Code Playgroud) 在WordPress 2.5及更高版本中,有一个内置的Gallery功能,允许选择将图像库添加到WordPress博客上的帖子或页面.(参考:http://codex.wordpress.org/Gallery_Shortcode)
您可以使用size选项指定要显示的缩略图大小.有效值包括"thumbnail","medium","large"和"full".默认为"缩略图".可以在WordPress管理面板中配置"缩略图","中"和"大"图像的大小.
即. [gallery size="medium"]
我的问题:我正在尝试破解[gallery]短代码,以便在输入时允许自定义大小 - 而不是尝试通过管理面板执行此操作.我想用类似的东西[gallery size="145x160"].
而不是下载一个膨胀的插件,我宁愿使用已经存在的东西,我不知道我需要在我的文件结构中进行哪些更改.我对PHP很熟悉,但我担心我会做出改变,然后当我更新WP的未来版本时,它会覆盖我在运动中设置的内容.
有人可以帮我解决这个问题吗?
非常感谢你!
我正在尝试制作一个短代码"插件" - 类似于Wordpress与TinyMce一起使用的代码.我希望用户能够通过按钮插入短代码(如[gallery id="3"]或[image id="9"]),然后显示占位符而不是实际的短代码.一旦我开始工作,我会将所有代码都放到github上.
我有一个按钮,使用insertHtml()这样的方式将html插入编辑器:
// Custom button code
CKEDITOR.instances['editor_instance_name'].insertHtml '<div class="media-library-gallery">[gallery id=' + gallery_id + ']</div>'
Run Code Online (Sandbox Code Playgroud)
并且我已添加extraAllowedContent以允许div我需要的类:
// CKEditor configuration (config.js)
config.extraAllowedContent = 'div(media-library-image,media-library-gallery)';
Run Code Online (Sandbox Code Playgroud)
我设法div.media-library-gallery使用以下代码替换图像:
(function() {
CKEDITOR.plugins.add('media_gallery', {
init: function(editor) {
CKEDITOR.addCss('.media_gallery{background: #f2f8ff url("/assets/gallery.png") no-repeat scroll center center; border: 1px dashed #888; display: block; width:100%; height: 250px;}');
},
afterInit: function( editor ) {
var dataProcessor = editor.dataProcessor;
var dataFilter = dataProcessor && dataProcessor.dataFilter;
dataFilter.addRules({ …Run Code Online (Sandbox Code Playgroud) shortcode ×10
wordpress ×7
php ×5
add-filter ×1
alphabetical ×1
ckeditor ×1
css ×1
gallery ×1
javascript ×1
menu ×1
tinymce ×1