[英]WordPress function to call a spefic part of the page content
I'm working on a simple website using WP and i don't know a way to call a specific part of the content.我正在使用 WP 开发一个简单的网站,但我不知道如何调用内容的特定部分。 I'll try to explain myself better.
我会尝试更好地解释自己。
Using the function:使用 function:
the_content();
in the.php file i can call the whole page content.在.php文件中我可以调用整个页面的内容。
I'm using a shortcode that simply create a div and i want to call in the.php file only the div created so that i can put it inside other divs etc.我正在使用一个简单地创建一个 div 的简码,我想在 .php 文件中调用仅创建的 div 以便我可以将它放在其他 div 等中。
Is there a function like the_content();
有没有像
the_content();
that only calls the shortcode?只调用简码?
Or, without using the shortcode, is there a way to call a portion of the page content using a WP function?或者,不使用简码,有没有办法使用 WP function 调用部分页面内容?
Here's the code:这是代码:
in the function.php
i have:在
function.php
我有:
function create_div($atts, $content = null) {
extract( shortcode_atts( array(
'class' => '',
'id' => '',
), $atts ) );
$class = $class ? " class=\"$class\"" : NULL;
$id = $id ? " id=\"$id\"" : NULL;
return "<div$class $id>$content</div>";
}
add_shortcode('div', 'create_div');
And in the page.php i want to do something like this:在 page.php 我想做这样的事情:
<div>
<?php the_shortcode(); ?>
</div>
Thanks, Andrea谢谢,安德里亚
You can use a shortcode directly in php using the do_shortcode()
function - see here: https://developer.wordpress.org/reference/functions/do_shortcode/ You can use a shortcode directly in php using the
do_shortcode()
function - see here: https://developer.wordpress.org/reference/functions/do_shortcode/
You can also try get_the_content()
to get everything into a variable and then extract what you need from there - see here: https://developer.wordpress.org/reference/functions/get_the_content/您也可以尝试
get_the_content()
将所有内容放入变量中,然后从那里提取您需要的内容 - 请参见此处: https://developer.wordpress.org/reference/functions/get_the_content/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.