admin管理员组文章数量:1289582
how are you?
I'm following a tutorial from GTCoding How to Make a Custom Website from Scratch using Wordpress (Theme Development) and I'm on the part of creating the projects page, that is starting at time 3:11:46.
The custom post type is working and I can see it as an option in the dashboard of the page and in the Home page all the post are shown, blogs and projects but, when I'm clicking in the projects page the title of the page shows "Page not found", then ad the body of the page it shows the title for the blogs but not any blog o project. Is important so say that the author created the theme in the way that the blogs page and the projects page loads the content of index.php whose content is the following
<?php get_header(); ?>
<main>
<a href="<?php echo site_url('/Home');?>">
<h2 class="page-heading">Todos los Blogs</h2>
</a>
<section>
<?php
while(have_posts()) {
the_post();
?>
<div class="card">
<div class="card-image">
<a href="<?php echo the_permalink(); ?>">
<img src="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>" alt="Card Image">
</a>
</div>
<div class="card-description">
<a href="<?php the_permalink(); ?>">
<h3><?php the_title(); ?></h3>
</a>
<div class="card-meta">
Posted by <?php the_author(); ?> a las <?php the_time('F j, Y') ?> el
<a href="#"><?php echo get_the_category_list(', ') ?></a>
</div>
<p><?php echo wp_trim_words(get_the_excerpt(), 30); ?></p>
<a href="<?php the_permalink(); ?>" class="btn-readmore">Leer más</a>
</div>
</div>
<?php
}
wp_reset_query();
?>
</section>
<div class="pagination">
<?php echo paginate_links(); ?>
</div>
<?php get_footer(); ?>
the code for creating the custom post type is in functions.php and is the following
<?php
// Adicionando los archivos CSS y JS
function gt_setup() {
wp_enqueue_style('google-fonts','//fonts.googleapis/css2?family=Roboto+Condensed:wght@300&family=Roboto+Slab:wght@100&family=Roboto:wght@100&display=swap');
wp_enqueue_style('fontawesome','.js');
wp_enqueue_style('style',get_stylesheet_uri(), NULL, microtime(), 'all');
wp_enqueue_script("main",get_theme_file_uri('/js/main.js'), NULL, microtime(), true);
}
add_action('wp_enqueue_scripts','gt_setup');
// Adding Theme Support
function gt_init() {
add_theme_support('post-thumbnails');
add_theme_support('title-tag');
add_theme_support('html5',
array('commen-list','comment-form','search-form')
);
}
add_action('after_setup_theme','gt_init');
// Project Post Type
function gt_custom_post_type() {
register_post_type('project',
array(
'rewrite' => array('slug' => 'projects'),
'labels' => array(
'name' => 'Projects',
'singular-name' => 'Project',
'add_new_item' => 'Add New Project',
'edit_item' => 'Edit Project'
),
'menu-icon' => 'dashicons-clipboard',
'public' => true,
'has-archive' => true,
'supports' => array(
'title', 'thumbnail', 'editor', 'excerpt', 'comments'
)
)
);
}
add_action('init', 'gt_custom_post_type');
the only way I managed to see the projects in the projects page is if I specifically put a while for printing the projects posts, something like the following
<?php
$args = array(
'post_type' => 'project',
'post_per_page' => 2
);
$projects = new WP_Query($args);
while($projects->have_posts()) {
$projects->the_post();
?>
<div class="card">
<div class="card-image">
<a href="<?php echo the_permalink(); ?>">
<img src="<?php echo get_the_post_thumbnail_url(get_the_ID()); ?>" alt="Card Image">
</a>
</div>
<div class="card-description">
<a href="<?php the_permalink(); ?>">
<h3><?php the_title(); ?></h3>
</a>
<div class="card-meta">
Posted by <?php the_author(); ?> a las <?php the_time('F j, Y') ?> el
<a href="#"><?php echo get_the_category_list(', ') ?></a>
</div>
<p><?php echo wp_trim_words(get_the_excerpt(), 30); ?></p>
<a href="<?php the_permalink(); ?>" class="btn-readmore">Leer más</a>
</div>
</div>
<?php
}
wp_reset_query();
?>
but then is bad printed because it prints the title of the blogs and the title of the projects in the same page.
The permalinks are working good apparently because if the permalink is clicked or written in the web explorer then the specific project page are loaded, just don't work by loading the projects page.
Update 18/07/21, 14:28:
If a new "Page" is added then when I press the link Porjects in the nav then the page "Projects" loads but without nothing because nothing is configure for that kind of page since the objective is to load the page as a custom post type
Update 19/07/21:
In the following image can be seen the outcome of running the plugin "List All URLs":
IMPORTANT NOTE: I'm not using the default wordpress installation but using Local.
How can this be solved?.
Thanks in advance for the help.
本文标签: theme developmentPage not found on custom post type page for projects
版权声明:本文标题:theme development - Page not found on custom post type page for projects 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741432471a2378443.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论