0
我剛開始使用wordpress開發一個項目。我想知道什麼是最好的做法,以顯示一組這樣的列(以紅色突出顯示)在wordpress中顯示元素組的最佳方式
在頁面(發佈)。我要求創建帖子的人可以插入帶有不同文本和標題的默認列。 我試過短代碼,但它似乎太複雜。我想要一些類似於輸入字段的東西,它們會生成列。謝謝
我剛開始使用wordpress開發一個項目。我想知道什麼是最好的做法,以顯示一組這樣的列(以紅色突出顯示)在wordpress中顯示元素組的最佳方式
在頁面(發佈)。我要求創建帖子的人可以插入帶有不同文本和標題的默認列。 我試過短代碼,但它似乎太複雜。我想要一些類似於輸入字段的東西,它們會生成列。謝謝
我用自定義帖子類型和簡碼解決了這個問題。
插件(可選 - 你可以手工編寫代碼的一切)
創建自定義職位類型和領域。 使用直觀的自定義帖子順序允許用戶重新排列帖子。
自定義此短代碼模板來匹配你的代碼,並要求:
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;
}