自定义帖子类型链接到页面发布wordpress二十一岁

时间:2017-09-28 10:45:38

标签: php wordpress hyperlink

所以我在这方面是一个完整的菜鸟但是非常努力并且似乎没有成功。接下来的十几个教程,它只是不起作用。

我使用的主题二十七岁

目前我正在使用本教程:[https://www.taniarascia.com/wordpress-from-scratch-part-two/][1]在我的functions.php中创建自定义帖子类型。 (成功了)完成了。

现在我复制了我的pages.php并将其重命名为:page-custom.php。 我在wordpress中有一个名为“自定义”的页面

此外,我已将设置调整为固定链接。

**Now i use this code:**

 <?php
 /**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0
 */

get_header(); ?>

<div class="wrap">
<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">




        <?php get_header(); ?>

<div class="row">
    <div class="col-sm-12">

        <?php
            $args =  array(
                'post_type' => 'my-custom-post',
                'orderby' => 'menu_order',
                'order' => 'ASC'
            );
             $custom_query = new WP_Query( $args );
        while ($custom_query->have_posts()) : $custom_query->the_post(); ?>

            <div class="blog-post">
                <h2 class="blog-post-title"><a href="<?php the_permalink(); 
?>"><?php the_title(); ?></a></h2>
                <?php the_excerpt(); ?>
            </div>

            <?php endwhile; ?>

    </div> <!-- /.col -->
</div> <!-- /.row -->

<?php get_footer(); ?>




    </main><!-- #main -->
</div><!-- #primary -->
</div><!-- .wrap -->

<?php get_footer();


 **And this is the original code**


<?php
 /**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package WordPress
  * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0
 */

get_header(); ?>

<div class="wrap">
<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">

        <?php
        while ( have_posts() ) : the_post();

            get_template_part( 'template-parts/page/content', 'page' );

            // If comments are open or we have at least one comment, load up 
the comment template.
            if ( comments_open() || get_comments_number() ) :
                comments_template();
            endif;

        endwhile; // End of the loop.
        ?>

    </main><!-- #main -->
</div><!-- #primary -->
</div><!-- .wrap -->

<?php get_footer();

我现在可以创建一个帖子,但是当我试图显示它时,我收到一条错误消息: “找不到oops页面”

如何将自定义帖子类型链接到要上传的特定页面?

Here is my function:
**function.php**

function create_my_custom_post() {
register_post_type( 'my-custom-post',
        array(
        'labels' => array(
                'name' => __( 'My Custom Post' ),
                'singular_name' => __( 'My Custom Post' ),
        ),
        'public' => true,
        'has_archive' => true,
        'supports' => array(
                'title',
                'editor',
                'thumbnail',
              'custom-fields'
        )
 ));
 }
 add_action( 'init', 'create_my_custom_post' );

1 个答案:

答案 0 :(得分:1)

尝试保存设置(/wp-admin/options-permalink.php)下的“永久链接”页面,让WP识别您的帖子类型。