我正在一个网站上工作,并且在模板文件中使用具有开头和结尾的短代码。我想知道是否可以在短代码之间放置 wordpress the_content php 标签,以及是否可以在开始和结束标签之间放置另一个短代码。
我试过这个 -
<?php echo do_shortcode('[membership level="1"]''.$the_content.''[/membership]'); ?>
Run Code Online (Sandbox Code Playgroud)
但这不起作用,我也尝试了其他一些方法。我错过了什么或做错了什么?任何帮助深表感谢。谢谢。
我创建包含HTML元素,如WordPress的网页<div>和<ul>如
<div id="main" class="large-12 medium-12 columns clearfix" role="main">
<h2 class="press-list-header">Articles</h2>
<ul class="press-list">
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
我想在这些HTML元素中放置短代码,如下所示:
<div id="main" class="large-12 medium-12 columns clearfix" role="main">
<h2 class="press-list-header">Articles</h2>
<ul class="press-list">
[picture image="http://example.com/image1.jpg" thumbnail="http://example.com/image1-thumbnail.jpg"]
[picture image="http://example.com/image2.jpg" thumbnail="http://example.com/image2-thumbnail.jpg"]
[picture image="http://example.com/image3.jpg" thumbnail="http://example.com/image3-thumbnail.jpg"]
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
当我这样做时,短代码只在渲染页面上显示为常规文本.如果我只是将短代码放在HTML元素之外,那么它们就可以正常地将预期内容呈现在页面上.
如何获取我的短代码以将其内容包装在HTML元素中?
我应该更具描述性.我希望我的客户能够轻松地在TinyMCE编辑器中输入简短的代码来获取页面和帖子.我不希望他们不得不处理php或html代码.他们无法访问这些.php模板文件,因为他们不是开发人员.我已经得到了短代码,只用于帖子而不是页面.我相信这样做的原因是我使用的模板调用custom-page.php了我的所有页面,如下所示:
<?php /* Template Name: Custom */ ?>
<?php get_header(); ?>
<div id="content">
<div id="inner-content" class="row clearfix">
<?php the_post(); global $post; echo $post->post_content; ?>
</div> <!-- end #inner-content -->
</div> <!-- end …Run Code Online (Sandbox Code Playgroud) 我想在简码中限制单词。我正在尝试在这里制作一个 WP 插件,我需要 get_the_excerpt{(); 中的有限单词;职能。
我想编辑WooCommerce Recent Products Shortcode,以便将查询限制为过去15天内发布的产品.我不知道该怎么做.这是短代码的代码:
/**
* Recent Products shortcode
*
* @param array $atts
* @return string
*/
public static function recent_products( $atts ) {
global $woocommerce_loop;
$atts = shortcode_atts( array(
'per_page' => '12',
'columns' => '4',
'orderby' => 'date',
'order' => 'desc'
), $atts );
$meta_query = WC()->query->get_meta_query();
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'ignore_sticky_posts' => 1,
'posts_per_page' => $atts['per_page'],
'orderby' => $atts['orderby'],
'order' => $atts['order'],
'meta_query' => $meta_query
);
ob_start();
$products = new WP_Query( apply_filters( …Run Code Online (Sandbox Code Playgroud) 我有以下短代码,用于在页面上显示自定义帖子:
add_shortcode( 'page-section', 'page_section_shortcode' );
function page_section_shortcode( $atts ) {
global $post;
$post_slug=$post->post_name;
$a = shortcode_atts( array(
'post-name' => 'qwerty',
'bg-color' => 'white'
), $atts );
$post_slug=$post->post_name;
$post_name = $a['post-name'];
$query = new WP_Query( array(
'post_type' => 'page_section',
'name' => $post_name,
) );
if ( $query->have_posts() ) { ?>
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div style="background-color: <?php echo $a['bg-color']; ?>" id="<?php global $post; $post_slug=$post->post_name; echo $post_slug; ?>" class="page-section">
<div class="row">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; …Run Code Online (Sandbox Code Playgroud) 我是一个新手,请帮助我创建一个 wordpress 图片短代码,就像这样简单:
[img src=""]
Run Code Online (Sandbox Code Playgroud)
它显示了它的缩略图(缩略图宽度=100%),链接到 OR 时打开相同的源图像,单击时。
我尝试搜索但在现有插件中找不到,如果有请指导我。
请彻底指导我在 function.php 或其他任何地方复制粘贴。
如果我有这个→
<input type="hidden" name="meta_adtracking" value="custom form" />
Run Code Online (Sandbox Code Playgroud)
然后我可以轻松地将其转换为可返回的字符串→
$output = '<input type="hidden" name="meta_adtracking" value="custom form" />'
Run Code Online (Sandbox Code Playgroud)
当然稍后会返回输出:
return $output;
Run Code Online (Sandbox Code Playgroud)
但是,当它具有jQuery或Wordpress本地化功能时,这对我来说变得具有挑战性.
<input type="submit" class="one" name="aweber_submit" value="<?php _e("Subscribe", 'text-domain');?>" />
Run Code Online (Sandbox Code Playgroud)
如何将上面的内容转换为可返回的字符串?[PS→实际上不需要php标签,因为短代码功能在.php扩展名的文件中],但是如果我只是删除一个PHP标签就可以了吗?
$output = '<input type="submit" class="one" name="aweber_submit" value="_e("Subscribe", 'text-domain');" />'
Run Code Online (Sandbox Code Playgroud)
这个可以吗?
我正在创建一个闪购网站,并且我已经在我的主页和商店页面上根据日期范围展示了产品。但我也想根据其他地方的日期范围显示产品,因此使用短代码。
这是我的代码:
function testt($meta_query)
{
$today = current_time('Ymd');
$args = apply_filters('woocommerce_shortcode_products_query', array (
'post_type' => 'product',
'numberposts' => -1,
'meta_query' => array(
'relation' => 'AND',
'start_clause' => array(
'key'=>'flash_sale_start',
'value' => $today,
'compare'=> '<=',
'type' => 'DATE'
),
'end_clause' => array(
'key' => 'flash_sale_end',
'value' => $today,
'compare' => '>=',
'type' => 'DATE'
),
)));
return $args;
}
add_shortcode( 'test', 'testt' );
Run Code Online (Sandbox Code Playgroud)
但它没有显示任何内容,甚至我的页面内容的其余部分都消失了。
我做错了什么?
任何帮助表示赞赏。
我是 WooCommerce 的新手,正在寻找一种在帖子页面上显示产品属性的解决方案。我进行了研究和一些测试,但似乎没有任何效果。
理想情况下,我想使用短代码获取产品 ID并在我的帖子页面上显示他的所有产品属性。就像是[product_page id="99" display_only_attributes ]
我需要通过产品的 id 检查产品的可见性状态。不仅仅是它是否可见,而是它是否被搜索、隐藏或可见。
我已经尝试过get_post_meta($id, '_visibility', true);,但是只有我的旧产品在数据库中具有该帖子元,所以我假设它不再使用。
这样做的总体原因是因为我试图用产品短代码显示产品,但没有选项可以在可见性内“显示全部”。例如,
echo do_shortcode('[products ids="' . $id . '" visibility="all"]');
Run Code Online (Sandbox Code Playgroud)
所以现在我必须检查产品的可见性并回显适当的短代码来显示它。除非我弄错了,并且有一种方法可以显示带有短代码的产品,无论它们的可见性如何......