WordPress内容无法正确显示

时间:2019-03-17 08:19:30

标签: wordpress

我陷入了Wordpress的问题。我创建了一个自定义帖子类型,然后上传了我的内容。但是当我在前端调用它们时,所有内容都可以正常工作。但是,当我添加 buildscript { repositories { maven { url "https://dl.bintray.com/android/android-tools" } } } 时,它显示为损坏。

自定义帖子类型(functions.php)

<?php the_content(); ?>

前端代码:

function sportify_custom_post(){
    register_post_type('intro' , array(
                'public'        => true, 
                'labels'        => array(
                    'name'      => 'Intro',
                    'all_items' => 'Intro Posts',
                    'add_new'   => 'Add intro post'
                ),
                'supports'      => array('title' , 'editor' , 'thumbnail')
            ));
        }
        add_action('init' , 'sportify_custom_post');

the content is looking like that

1 个答案:

答案 0 :(得分:0)

将此代码用于functions.php

function intro_custom_post() {
$labels = array(
'name'               => _x( 'name post type', 'post type general name' ),
'singular_name'      => _x( 'about', 'post type singular name' ),
'add_new'            => _x( 'new', 'about' ),
'add_new_item'       => __( 'new' ),
'edit_item'          => __( 'edit' ),
'new_item'           => __( 'new item' ),
'all_items'          => __( 'all items' ),
'view_item'          => __( 'view item' ),
'search_items'       => __( ' search' ),
'not_found'          => __( 'not found' ),
'not_found_in_trash' => __( 'not found in trash' ),
'featured_image'     => __( 'featured image' ),
'set_featured_image' => __( 'set featured image' ),
'remove_featured_image'     => __( 'remove featured image' ),
'parent_item_colon'  => '',
'menu_name'          => 'menu name'
);
$args = array(
'labels'        => $labels,
'description'   => 'save',
'public'        => true,
'menu_position' => 5,
'supports'      => array( 'title', 'thumbnail','editor','excerpt'),
'has_archive'   => true,
);
register_post_type( 'intro', $args );
}
add_action( 'init', 'intro_custom_post' );

将此代码用于前端

    <?php
    $args = array( 
    'post_type' => 'intro',
    'posts_per_page' => 18 , 
    );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post(); ?>   
    <!-- Intro Box -->
    <div class="intro_box d-flex flex-column align-items-center justify-content-center text-center">
        <?php the_post_thumbnail(); ?>
        <div class="intro_box_title"><h3><?php the_title(); ?></h3></div>
        <div class="intro_box_text">
            <?php the_content(); ?>
        </div>
    </div>
    <?php endwhile; wp_reset_query(); ?>