0
所以我是一個完整的noob在這個但非常努力,並且似乎沒有成功。跟着十幾個教程,它不會工作。自定義帖子類型鏈接到頁面發佈WordPress的二十七
的主題,我使用的是twentyseventeen
目前我使用本教程:[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();
我現在可以創建一個帖子,但是當我試圖證明它,我得到一個錯誤信息: 「哎呀頁面不存在」
如何鏈接的自定義後鍵入要上傳到的特定頁面?
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');
您如何訪問該頁面?通過轉到您在WP後端創建的'custom'頁面的視圖鏈接? – Junaid
你創建頁面slu or或永久鏈接必須是自定義的,它必須工作 –
我通過vieuw鏈接訪問該頁面。在wordpress中。 –