Plugins 如何获得wordpress之外的快捷码?

Plugins 如何获得wordpress之外的快捷码?,plugins,wordpress,shortcode,Plugins,Wordpress,Shortcode,如何获得wordpress之外的快捷码 这是我的密码 <?php require($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php'); $args = array( 'posts_per_page' => 10 // Specify how many posts you'd like to display ); $latest_posts = new WP_Query( $args ); if ( $latest_posts->

如何获得wordpress之外的快捷码

这是我的密码

<?php 
require($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php'); 
$args = array(
    'posts_per_page' => 10 // Specify how many posts you'd like to display
);
$latest_posts = new WP_Query( $args );  
if ( $latest_posts->have_posts() ) {
    while ( $latest_posts->have_posts() ) {
        $latest_posts->the_post();
if (preg_match_all ("#\[scode\](.+)\[\/scode\]#", the_content(), $matches, PREG_SET_ORDER)) {
echo $matches[1];
};
?>

任何人都可以帮助我…

如果我正确理解你的问题,你应该使用。它返回一个字符串,因此您可以像这样调用它:

在您的示例中,您可能可以执行以下操作:

<?php 
    require($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php'); 
    $args = array(
        'posts_per_page' => 10 // Specify how many posts you'd like to display
    ;
    $latest_posts = new WP_Query( $args );  
    if ( $latest_posts->have_posts() ) {
        while ( $latest_posts->have_posts() ) {
            $latest_posts->the_post();
    if (preg_match_all ("#". do_shortcode('[scode]') ."(.+)". do_shortcode('[scode]') ."#", the_content(), $matches, PREG_SET_ORDER)) {
    echo $matches[1];
    };
?>

这是可能的。有一个composer包,允许您在任何PHP应用程序中创建类似wordpress的短代码:


你可以在这里找到一个教程:

我不想使用do_短代码,我正在我的插件中使用这段代码=添加_短代码('scode','my_function');现在,我怎样才能在scode下获得这段代码呢?只需调用短代码所连接的函数,并通过短代码将通常需要的参数传递给它即可。更好的问题是,为什么需要在WordPress之外显示这些帖子?我打赌你可以创建一个自定义模板来满足你的需要。
<?php 
    require($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php'); 
    $args = array(
        'posts_per_page' => 10 // Specify how many posts you'd like to display
    ;
    $latest_posts = new WP_Query( $args );  
    if ( $latest_posts->have_posts() ) {
        while ( $latest_posts->have_posts() ) {
            $latest_posts->the_post();
    if (preg_match_all ("#". do_shortcode('[scode]') ."(.+)". do_shortcode('[scode]') ."#", the_content(), $matches, PREG_SET_ORDER)) {
    echo $matches[1];
    };
?>