【问题标题】:Best way to display group of elements in wordpress在 wordpress 中显示元素组的最佳方式
【发布时间】:2017-05-26 10:23:41
【问题描述】:

我刚刚开始使用 wordpress 开展一个项目。我想知道显示一组这样的列(以红色突出显示)

的最佳做法是什么

在页面(帖子)中。我要求创建帖子的人可以插入具有不同文本和标题的默认列。 我尝试了简码,但它似乎太复杂了。我想要带有输入字段的表单之类的东西,它将生成列。谢谢

【问题讨论】:

    标签: wordpress wordpress-theming custom-wordpress-pages


    【解决方案1】:

    我使用自定义帖子类型和简码解决了这个问题。

    插件(可选 - 您可以手动编写所有代码)

    • 自定义帖子类型和自定义字段创建者 - WCK
    • 直观的自定义发布顺序

    创建您的自定义帖子类型和字段。 使用直观的自定义帖子顺序允许用户重新排序帖子。

    自定义此简码模板以匹配您的代码和要求:

    add_shortcode('cpt-list', 'jpro_cpt_list'); 
    
    function jpro_cpt_list() {
    
        $args = array ( 
            'post_type' => array( 'cpt' ), 
            'posts_per_page' => '-1', 
            'orderby' => 'menu_order', 
            'order'   => 'ASC' 
        );
        $query = new WP_Query( $args );
    
        $cpt_list = '<div class="jpro-cpt cpt-list container">';    
    
        if ( $query->have_posts() ) {                                   
            while ( $query->have_posts() ) {
                $query->the_post(); 
    
                $post   = get_post($id);
                $postID = $post->ID;
    
                $image  = get_the_post_thumbnail( $postID, 'medium', array( 'class' => 'aligncenter' ));
                $name   = get_the_title($postID);   
                $bio    = apply_filters('the_content', $post->post_content); 
    
    
                if(!empty($image)){ 
                    $output_image = '<div class="cpt-list image">'.$image.'</div>';
                } else {
                    $output_image = '';
                }
    
                if(!empty($name)){
                    $output_name ='<h3 class="cpt-name cpt-list">'.$name.'</h3>';
                } else {
                    $output_name = '';
                }
    
                if(!empty($bio)){
                    $output_bio ='<div class="cpt-bio cpt-list">'.$bio.'</div>';
                } else {
                    $output_bio = '';
                }
    
                    $cpt_list .= '<section class="jpro-cpt cpt-list columnClass">';
                    $cpt_list .= $output_image;
                    $cpt_list .= $output_name;
                    $cpt_list .= $output_bio;               
                    $cpt_list .= '</section>';
    
            }   
        } else {
            $cpt_list .='<p>Ooops! No cpt Found.</p>';
        }
    
        $cpt_list .='</div>';       
        wp_reset_postdata();
        return $cpt_list;
    
    }
    

    【讨论】:

      猜你喜欢
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 2014-09-30
      • 1970-01-01
      • 1970-01-01
      • 2010-11-15
      • 1970-01-01
      • 2020-10-02
      相关资源
      最近更新 更多