Jquery 通过自定义内容类型循环的自定义短代码

Jquery 通过自定义内容类型循环的自定义短代码,jquery,html,wordpress,shortcode,Jquery,Html,Wordpress,Shortcode,我有一个使用Wordpress自定义内容快捷码插件的网站。它有一些不兼容的地方,已经关闭了我们的网站好几次了。我正在做以下工作: [loop type=“th\u sermons”taxonomy=“th\u sermons\u speaker”value=“speaker slug”count=“5”] [如果为空] 这一类没有布道。 [其他] [if] [/loop] 当它工作时,它工作得很好,但是关闭站点并不是一个好结果。我认为编写一个定制的短代码来实现这一点是很容易的。像这样的

我有一个使用Wordpress自定义内容快捷码插件的网站。它有一些不兼容的地方,已经关闭了我们的网站好几次了。我正在做以下工作:

[loop type=“th\u sermons”taxonomy=“th\u sermons\u speaker”value=“speaker slug”count=“5”]
  • [如果为空] 这一类没有布道。 [其他]
  • [if] [/loop]
    当它工作时,它工作得很好,但是关闭站点并不是一个好结果。我认为编写一个定制的短代码来实现这一点是很容易的。像这样的

    [rlcf\u布道演讲者=“演讲者鼻涕虫”计数=“可选的\u或\u数字”]
    
    谁能给我指一下正确的方向吗


    谢谢

    这将为您指明在主题
    functions.php
    文件中添加自定义短代码的正确方向:

    add_shortcode( 'rlcf_sermons', function( $atts ){
    
        // set default attributes
        extract( shortcode_atts( array(
            'speaker' => '',
            'count'   => -1
        ), $atts ) );
    
        // query
        $sermons = new WP_Query(array(
            'post_type' => 'th_sermons',
            'tax_query' => array(
                array(
                    'taxonomy' => 'th_sermons_speaker',
                    'field'    => 'slug',
                    'terms'    => $speaker
                )
            ),
            'posts_per_page' => $count
        ));
    
        // output
        if($sermons->have_posts()):
    
            while ( $sermons->have_posts() ) :
                $sermons->the_post();
                // here goes all the code you want for each LI tag
                echo '<li>' . get_the_title() . '</li>';
            endwhile;
    
            wp_reset_postdata();
    
        else: echo 'There are no sermons for this category.';
    
        endif;
    
    } );
    
    add_shortcode('rlcf_布道',函数($atts){
    //设置默认属性
    提取(短码)附件(数组)(
    “演讲者”=>“,
    “计数”=>-1
    )美元(附件);;
    //质疑
    $sermons=新的WP\u查询(数组(
    “post_type”=>“th_布道”,
    “tax_query”=>数组(
    排列(
    “分类法”=>“讲道者”,
    '字段'=>'段塞',
    “术语”=>$speaker
    )
    ),
    “每页帖子数”=>$count
    ));
    //输出
    如果($布道->有帖子()):
    而($布道->发帖子()):
    $布道->_post();
    //下面是每个LI标记所需的所有代码
    回显“
  • ”。获取标题(); 结束时; wp_reset_postdata(); 其他:echo“这一类没有布道”; endif; } );

  • 参考资料:和。

    非常感谢。代码的“查询”部分正在使网站崩溃。可能发生了什么?在
    “每页帖子”之前有一个拼写错误,一个逗号丢失了
    。但是,您应该激活,以便在出现这些错误时能够找到。谢谢。我刚贴完这张照片就找到了。我真的很感谢你的帮助!