Carlos Llanos
asked on
WordPress - Timber - Single post not rendering
I am trying to render a single post: single-walkthroughs.php -> single-walkthroughs.twig however the page displays: "Sorry, we couldn't find what you're looking for."
Here's what I have:
code that renders the custom post type in functions.php
Code that renders walkthroughs page
page-walkthroughs.php
page-walkthroughs.twig
Code that SHOULD render a single page
single-walkthroughs.php
single-walkthroughs.twig
Any help is appreciated.
Here's what I have:
code that renders the custom post type in functions.php
$labels = array(
'name' => 'Walkthroughs',
'singular_name' => 'Walkthrough',
'menu_name' => 'Walkthroughs',
'name_admin_bar' => 'Walkthrough',
'add_new' => 'Add New',
'add_new_item' => __( 'Add New Walkthrough' ),
'new_item' => __( 'New Walkthrough' ),
'edit_item' => __( 'Edit Walkthrough' ),
'view_item' => __( 'View Walkthrough' ),
'all_items' => __( 'All Walkthroughs' ),
'search_items' => __( 'Search Walkthroughs' ),
'parent_item_colon' => __( 'Parent Walkthroughs:' ),
'not_found' => __( 'No walkthroughs found.' ),
'not_found_in_trash' => __( 'No walkthroughs found in Trash.' )
);
$args = array(
'labels' => $labels,
'description' => __( 'Walkthroughs.'),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'walkthroughs' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'menu_icon' => 'dashicons-list-view',
'taxonomies' => array( 'category' ),
'supports' => array( 'title', 'editor', 'thumbnail' )
);
register_post_type( 'walkthroughs', $args );
Code that renders walkthroughs page
page-walkthroughs.php
<?php
$context = Timber::get_context();
$args = array(
'post_type' => 'walkthroughs',
);
$context['posts'] = Timber::get_posts($args);
Timber::render( array( 'page-' . $post->post_name . '.twig', 'page.twig' ), $context );
page-walkthroughs.twig
{% extends "base.twig" %}
{% block content %}
<div class="content-wrapper">
<article class="post-type-{{post.post_type}}" id="post-{{post.ID}}">
<section class="article-content">
<h1 class="article-h1">{{post.title}}</h1>
<div class="article-body">
{{post.content}}
</div>
</section>
</article>
</div><!-- /content-wrapper -->
<div>
{% for post in posts %}
<h2><a href="{{ post.link }}">{{ post.post_title }}</a></h2>
<div>{{ post.post_content|wpautop }}</div>
{% endfor %}
</div>
{% endblock %}
Code that SHOULD render a single page
single-walkthroughs.php
<?php
$context = Timber::get_context();
$post = Timber::query_post();
$context['post'] = $post;
if ( post_password_required( $post->ID ) ) {
Timber::render( 'single-password.twig', $context );
} else {
Timber::render( array( 'single-' . $post->post_type . '.twig', 'single.twig' ), $context );
}
single-walkthroughs.twig
{% extends "base.twig" %}
{% block content %}
<div class="content-wrapper">
<article class="post-type-{{post.post_type}}" id="post-{{post.ID}}">
<section class="article-content">
<h1 class="article-h1">{{post.title}}</h1>
<p class="blog-author">
<span>By</span><a href="{{post.author.path}}"> {{ post.author.name }} </a><span>•</span> {{ post.post_date|date}}
</p>
<div class="article-body">
{{post.content}}
</div>
</section>
</article>
</div><!-- /content-wrapper -->
{% endblock %}
Any help is appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER