我有一个代码来显示随机引用.一个人写了一个函数来实现所有这些.但由于某些原因,通过AJAX更新数据不起作用.当您按下"新报价"按钮时,没有任何反应.也许有人知道为什么?需要在以下代码中修复哪些内容,以便在单击"新引号"时加载新引号?
/wp-content/themes/%your_theme%/js/ajax-load-quote.php
<?php
/* uncomment the below, if you want to use native WP functions in this file */
// require_once('../../../../wp-load.php');
$array = file( $_POST['file_path'] ); // file path in $_POST, as from the js
$r = rand( 0, count($array) - 1 );
return '<p>' . $array[$r] . '</p>';
?>
Run Code Online (Sandbox Code Playgroud)
在页面内容,窗口小部件或模板文件中:
<div id="randomquotes">
<p>I would rather have my ignorance than another man’s knowledge,
because I have so much more of it.<br />
-- Mark Twain, American author & …Run Code Online (Sandbox Code Playgroud) 寻找一个PHP函数(非jQuery或wpautop修改)方法<p></p>从wordpress中删除.
我试过这个,但它不起作用:
function cleanup_shortcode_fix($content) {
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']',
']<br>' => ']'
);
$content = strtr($content, $array);
return $content;
}
add_filter('the_content', 'cleanup_shortcode_fix');
Run Code Online (Sandbox Code Playgroud) 我正在尝试将echo视觉作曲家shortcodes放到页面上.
我已尝试过以下两种方法,但它们不起作用:
的functions.php:
方法1
/*
* add shortcode file
*/
function include_file($atts) {
$a = shortcode_atts( array(
'slug' => 'NULL',
), $atts );
if($slug != 'NULL'){
ob_start();
get_template_part($a['slug']);
return ob_get_clean();
}
}
add_shortcode('include', 'include_file');
Run Code Online (Sandbox Code Playgroud)
方法2
function someshortocode_callback( $atts = array(), $content = null ) {
$output = "[vc_section full_width=\"stretch_row\" css=\".vc_custom_1499155244783{padding-top: 8vh !important;padding-bottom: 5vh !important;background-color: #f7f7f7 !important;}\"][vc_row 0=\"\"][vc_column offset=\"vc_col-lg-offset-3 vc_col-lg-6 vc_col-md-offset-3 vc_col-md-6\"][/vc_column][/vc_row][/vc_section]";
return $output;
}
add_shortcode('someshortocode', 'someshortocode_callback');
Run Code Online (Sandbox Code Playgroud)
file_rendering_vc_shortcodes.php:
方法1
<?php if ( is_plugin_active( 'js_composer/js_composer.php' ) ) { …Run Code Online (Sandbox Code Playgroud) 我创建了一些短代码元素。现在我想在后端编辑器中自定义元素的外观。
从VC-Pagebuilder wiki的描述中,我发现我可以为此使用“custom_markup”参数。
对于简单的 html,它工作正常。但是我无法在简码后端元素中显示用户输入。
<?php
add_shortcode('simpletext', 'simpletext_shortcode');
add_action('vc_before_init', 'simpletext_vc');
// Frontend output
function simpletext_shortcode($atts, $content = '') {
ob_start();
set_query_var('content', $content);
get_template_part('components/content', 'simpletext');
return ob_get_clean();
}
// Backend
function simpletext_vc() {
vc_map(array(
"name" => "Einfacher Text",
"base" => "simpletext",
"class" => "",
"icon" => get_template_directory_uri() ."/images/vc_icons/simpletext_icon.png",
"custom_markup" => '{{ content }}', // try to display the user input
"category" => "Text",
"params" => array(
array(
"param_name" => "content",
"heading" => "Inhalt",
"description" => "Inhalt des Elements.",
"holder" …Run Code Online (Sandbox Code Playgroud) php wordpress wordpress-theming custom-wordpress-pages shortcode
联系表格7有一些短代码,比如[_date]来获取今天的日期.但我想在一周后显示日期.
因此,我需要为联系表单7创建一个自定义短代码,其中显示[next_week],并在收到的电子邮件中显示正确的日期.
我在何处以及如何创建自定义短代码以联系表单7?
我刚刚发现两者echo并return正常工作从一个简码功能显示内容.
function foobar_shortcode($atts) {
echo "Foo Bar"; //this works fine
}
function foobar_shortcode($atts) {
return "Foo Bar"; //so does this
}
Run Code Online (Sandbox Code Playgroud)
我只是想知道,使用其中任何一个之间有什么区别吗?如果是这样的推荐是什么?在这种情况下我通常使用echo; 好吗?
我想通过循环外的id获取帖子内容,所以我使用以下代码:
echo get_post_field('post_content', $postid);
Run Code Online (Sandbox Code Playgroud)
它工作正常,但是,如果帖子包含任何短代码,则短代码无法正常工作.它只将短代码作为纯文本回显.
示例:我在编辑器中使用以下代码在图像中显示图像和标题文本:
[caption id="attachment_23" align="alignnone" width="300"]<img class="size-medium wp-image-23 " alt="" src="http://localhost/wordpress/wp-content/uploads/2014/03/Desert-300x225.jpg" width="300" height="225" /> this is caption[/caption]
Run Code Online (Sandbox Code Playgroud)
但是当我使用函数获取此帖子内容时get_post_field(),它显示:而不是显示标题文本.
[caption id="attachment_23" align="alignnone" width="300"]this is caption[/caption]
Run Code Online (Sandbox Code Playgroud)
有解决方案吗
注意:我正在使用ajax来获取内容
我正在创建一些WordPress短代码,旨在提供页面上的内部导航(一页有很多内容部分和它自己的菜单).
这就是我所拥有的:
//menu
function internal_menu($atts) {
extract(shortcode_atts(array(
'href1' => '#jl1',
'href2' => '#jl2',
'href3' => '#jl3',
'href4' => '#jl4',
), $atts));
return '<div id="internalPageMenu">
<ul>
<li><a href="' . $href1 . '"><i class="fa fa-bars"></i>link 1</a></li>
<li><a href="' . $href2 . '">link 2</a></li>
<li><a href="' . $href3 . '">link 3</a></li>
<li><a href="' . $href4 . '">link 4</a></li>
</ul>
</div>';
}
add_shortcode('internal-menu', 'internal_menu');
//menu target
function internal_menu_target($atts) {
extract(shortcode_atts(array(
'id' => 'jl1',
'text' => '',
), $atts));
return '<h3 id="' . $id . …Run Code Online (Sandbox Code Playgroud) 我有一个页面,我需要允许用户输入一段文字.然后在该文本之后插入一个将呈现帖子列表的短代码,然后添加更多自由格式文本.我的想法是他们应该能够插入一个输出帖子的短代码.这样他们就可以简单地在他们希望帖子出现的地方添加短代码.
我目前有逻辑检索在自己的文件中分隔的帖子.目前我只需使用以下get_template_part()功能将其包含在页面中:
get_template_part('donation', 'posts');
Run Code Online (Sandbox Code Playgroud)
我研究了如何创建一个短代码,并在我的functions.php文件中包含以下代码以创建短代码:
add_shortcode('donation-posts', 'fnDonatePosts');
function fnDonatePosts($attr, $content)
{
get_template_part('donation', 'posts');
}
Run Code Online (Sandbox Code Playgroud)
在donation-posts.php该短码被放置的位置被正确执行和职位出现,但是,他们总是定位在内容之前不能及的.
我已经尝试删除该get_template_part()功能,只输出一些文本,并且工作正常.所以我明白这get_template_part()可能不是正确的方法,但是,我还没有找到办法去做我想做的事情(我确信有办法...我只是避风港'找到它).
我试过了:
include(get_template_directory(). '/donation-posts.php');
include_once(get_template_directory(). '/donation-posts.php') :
Run Code Online (Sandbox Code Playgroud)
但是一旦他们点击了包含文件中的PHP代码,这些就停止了处理.
我也尝试过:
$file = file_get_contents(get_template_directory(). '/donation-posts.php');
return $file;
Run Code Online (Sandbox Code Playgroud)
但这只返回文件的内容(如函数名所示),这意味着它不会执行 PHP脚本来返回帖子.
以前有人这样做过吗?
我只想在我的wordpress主题菜单栏中添加一个短代码按钮来处理该bootstrap modal view功能.
我试过' Shortcodes in Menus'插件,但它不起作用.我找不到菜单中短代码的替代插件,所以我安装了' Bootstrap 3 Shortcodes'插件,它创建了按钮和模态视图内容,如我所愿.但我无法在我的菜单栏中添加短代码.
我努力尝试找到一些关于我的问题的答案.但遗憾的是不可能.
这是由Bootstrap 3 Shortcodes插件生成的模态短代码 ;
[modal text="Download Now" title="Veteriner Hekimlere Ula?man?n En Kolay Yolu" xclass="btn btn-primary btn-lg"]
<p style="text-align: center;"><img src="http://web-test.vetmapp.com/wp-content/uploads/sites/2/2016/08/vetmapp-logo-withtext.png" alt="Logo" width="200" height="300" /></p>
<h4 style="text-align: center;">VetMapp'i cihaz?n?za göre a?a??daki platformlardan cep telefonunuza ücretsiz olarak indirebilir ve hemen kullanmaya ba?layabilirsiniz.</h4>
<p style="text-align: center;">
<a href="https://itunes.apple.com/tr/app/vetmapp-acil-veteriner-klinikleri/id969463902?mt=8" target="_blank"><img src="http://web-test.vetmapp.com/wp-content/uploads/sites/2/2016/09/180x40xapple-store.png.pagespeed.ic.z0I7tHw8h6.png" alt="App Store'dan indir!" width="135" height="40" /></a>
<a href="https://play.google.com/store/apps/details?id=com.esmobileinc.vetmapp&hl=tr"
target="_blank"><img src="http://web-test.vetmapp.com/wp-content/uploads/sites/2/2016/09/180x40xgoogle_play.png.pagespeed.ic.31v8JAmtbI.png" alt="Google Play'den indir!" width="135" height="40" …Run Code Online (Sandbox Code Playgroud)