有谁知道如何在tinymce中为Wordpress创建自定义下拉框?我需要它至少与wordpress 3.0一起使用。
我已经在互联网上搜索了关于此的教程,但找不到。链接到网站教程会很棒。
提前致谢。
我想[gallery]在我的博文中删除短代码.我发现的唯一解决方案是我添加到我的函数中的过滤器.
function remove_gallery($content) {
if ( is_single() ) {
$content = strip_shortcodes( $content );
}
return $content;
}
add_filter('the_content', 'remove_gallery');
Run Code Online (Sandbox Code Playgroud)
它删除了所有短代码,包括[caption]我需要的图像.如何指定要排除或包含的单个短代码?
我目前正在尝试为WordPress创建一个创建标签的短代码,我知道有可用的短代码.但我正在努力学习如何自己编写它们.
目前我正在生成标签菜单项,但我坚持将内容放在一个全新的div中.
前端用法:
[tabs]
[tab title="tab" active="y" id="home"]home[/tab]
[tab title="tab2" active="n" id="about"]about[/tab]
[tab title="tab3" active="n" id="help"]help[/tab]
[/tabs]
Run Code Online (Sandbox Code Playgroud)
然后是代码:
function tabs_group( $atts, $content = null ) {
extract(shortcode_atts(array(
'id' => '',
'class' => ''
), $atts));
$output = '<ul class="nav nav-tabs '.$class.'" ';
if(!empty($id))
$output .= 'id="'.$id.'"';
$output .='>'.do_shortcode($content).'</ul>';
return $output;
}
add_shortcode("tabs", "tabs_group");
function tab($atts, $content = null) {
extract(shortcode_atts(array(
'id' => '',
'title' => '',
'active'=>'n'
), $atts));
if(empty($id))
$id = 'tab_item_'.rand(100,999);
$output = '<li class="'.($active == 'y' ? …Run Code Online (Sandbox Code Playgroud) 我花了大约2个小时搜索javascript,这将为我提供简单的选项,为textarea添加新的"onclick,插入文本"按钮,但不幸的是我无法找到我想要的东西.
我有textarea:
<textarea name="user-submitted-content" rows="5" data-required="true" placeholder="<?php _e('Post Content', 'usp'); ?>" class="usp-textarea"></textarea>
Run Code Online (Sandbox Code Playgroud)
我想要这样的javascript:
var newText = "[" + shortcode + "]" + selectedText + "[/" + shortcode + "]";
Run Code Online (Sandbox Code Playgroud)
而且我可以添加如下按钮:
<input type="button" value="youtube" onclick="formatText ('youtube');" />
<input type="button" value="text" onclick="formatText ('text');" />
Run Code Online (Sandbox Code Playgroud)
当我点击"youtube"按钮时,它应该[youtube][/youtube]在textarea中添加/插入:
上面的代码我从一个javascript示例中获取了一个带有标签的textarea选定文本:
<script type="text/javascript">
<!--
function formatText (tag) {
var selectedText = document.selection.createRange().text;
if (selectedText != "") {
var newText = "[" + tag + "]" + selectedText + "[/" + tag + "]";
document.selection.createRange().text = …Run Code Online (Sandbox Code Playgroud) 我为 WordPress 编写的短代码有问题。我正在尝试使用该get_the_content()函数,但不是提取我创建的自定义帖子类型的内容,而是提取短代码所在页面的内容。其他功能都工作正常,例如get_the_title()和 g et_the_post_thumbnail()。我在函数中传递了 ID,它对于其他一切都非常有效,只是不适用get_the_content。
get_the_content($testimonial_item->ID);
Run Code Online (Sandbox Code Playgroud)
短代码包含分页和其他元素,它们都可以正常工作,只是这个功能让我感到悲伤。完整的代码如下,任何帮助将不胜感激。
function ncweb_display_testimonial_items($atts, $content = null) {
extract( shortcode_atts( array(
'per_page' => 6
), $atts ) );
/* pagination parameters */
// check what page we are on
if ( isset ($_GET['testimonial-page'] ) ) $page = $_GET['testimonial-page']; else $page = 1;
// default number of pages
$total_pages = 1;
// portfolio offset. Used in the get_posts() query to show only portfolio for the current page
$offset …Run Code Online (Sandbox Code Playgroud) 在WordPress中,我在编辑器中有一个操作短代码按钮,我希望它的功能一旦点击,就会在光标的最后一个位置附加两个短代码标签(一个开头,一个在末尾),但我一直无法找到关于该主题的先前问答,我已经引用了命令标识符的TinyMCE文档.这是我的shortcode.js文件:
(function() {
tinymce.PluginManager.add('foobar', function(editor, url) {
editor.addButton('foobar', {
title : 'This is just a test',
text : '<foobar>',
icon : false,
onclick : function() {
editor.execCommand(
"mceInsertContent",
false,
'[foobar][/foobar]'
);
}
});
});
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
因此,一旦<foobar>单击该按钮,它将生成:
<foobar></foobar>cursor is here
Run Code Online (Sandbox Code Playgroud)
关闭后光标即将到来</foobar>.我在编辑器中使用了错误的方法吗?这可能是一个相关的问题,但如果我想构建另一个短代码,它会添加三行,甚至有一种方法,例如:
<foobar>
<!-- Cursor lands here
</foobar>
Run Code Online (Sandbox Code Playgroud)
在tinyMCE中控制光标位置的适当命令是什么?
我遇到的问题是,短代码只是回显而不是执行,即这是我在网页上实际看到的内容:
[ajax_filter_posts per_page ="10"]
这是我的function.php文件http://termbin.com/v6v5
//enqueue and localizing the Javascript.
function assets() {
wp_enqueue_script('ajax_filter_post_mdu', get_template_directory_uri() . '/js/ajax-filter-posts.js', ['jquery'], null, true);
wp_localize_script( 'ajax_filter_post_mdu', 'bobz', array(
'nonce' => wp_create_nonce( 'bobz' ),
'ajax_url' => admin_url( 'admin-ajax.php' )
));
}
add_action('wp_enqueue_scripts', 'assets', 100);
Run Code Online (Sandbox Code Playgroud)
以下是我在个人类别template.php http://termbin.com/8r3x中调用短代码的方法
<?php echo do_shortcode('?ajax_filter_posts per_page="10"?'); ?>
Run Code Online (Sandbox Code Playgroud)
根据我的理解,我做错了什么,也许是在排队和本地化,但我不明白哪里是错误.此外,javascript正确加载,因为浏览器不会抱怨找不到该文件.
另外在我的模板category.php文件中,我直接调用函数,例如:
<?php $a = array('post_tag', false, false);
$pub_tag = vb_filter_posts_sc( $a );
echo $pub_tag;
?>
Run Code Online (Sandbox Code Playgroud)
它确实工作正常......
我已经分享了2016 Wordpress内置主题和黑客攻击,我在某处发生了冲突吗?
我尽可能多地搜索,但无法将其整理出来.
我为wordpress构建了一个非常独特且javascript密集的主题,现在短信不起作用.我没有安装任何插件,所以不是这样.我从使用短代码所需的wordpress模板文件中删除了什么(即:[gallery]).
我理解如何制作短代码,但是当WP将其吐出来展示时,WP如何接受你的帖子并替换"[gallery]"?
编辑:这是我目前正在使用的:
$pagepull = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'page' AND post_status = 'publish' ORDER BY menu_order", ARRAY_A);
$i = 1;
foreach ($pagepull as $single_page){
echo "<div class=\"section\"><ul><li class=\"sub\" id=\"" . $i . "\"><div class=\"insection\">";
echo $single_page['post_content'];
$i++;
// more code that is irrelevant...
// more code that is irrelevant...
// more code that is irrelevant...
}
Run Code Online (Sandbox Code Playgroud) 我有一个字符串可能包含短代码,例如"这是一个带[anyshortcode1]的字符串,这是[anyshortcode2]".我想显示字符串,其中包含运行放置位置的短代码.当我回显这个字符串时,它不会执行短代码,只是将它们打印出来,将它们留在括号中.我试图通过使用如下代码来解决这个问题:
$string_with_shortcodes = "this is a string with [anyshortcode1] and this is [anyshortcode2]";
$pattern = get_shortcode_regex();
preg_match_all("/$pattern/",$string_with_shortcodes, $matches);
foreach ($matches[0] as $short) {
$string_with_shortcodes = str_replace($short, 'do_shortcode("' . $short . '")', $string_with_shortcodes);
}
eval("\$string_with_shortcodes = \"$string_with_shortcodes\";");
echo $string_with_shortcodes;
Run Code Online (Sandbox Code Playgroud)
这会成功执行字符串替换,但会导致eval函数出错:
解析错误:语法错误,意外T_STRING
我使用eval函数错了吗?或者是否有更简单的方法来完成从字符串运行短代码?
我在Wordpress中为自定义菜单创建了一个短代码.
问题是我的$菜单显示在side-nav和side-nav-menu div的上方和外部.
我试过回复/返回它而不将其存储在$ var中我得到了同样的问题.
我错过了什么吗?
function custom_menu() {
$menu = wp_nav_menu( array( 'theme_location' => 'product-menu' ) );
$var = '<div class="side-nav">
<div class="side-nav-menu product- nav">
<p>Products</p>' . $menu . '
</div></div>';
return $var;
}
add_shortcode("custom", "custom_menu");
Run Code Online (Sandbox Code Playgroud)