Link to home
Start Free TrialLog in
Avatar of Carlos Llanos
Carlos LlanosFlag for United States of America

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
$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 );

Open in new window


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 );

Open in new window


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 %}

Open in new window


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 );
}

Open in new window


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>&bull;</span> {{ post.post_date|date}}
                </p>
                <div class="article-body">
                    {{post.content}}
                </div>
            </section>
        </article>
    </div><!-- /content-wrapper -->
{% endblock %}

Open in new window


Any help is appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Carlos Llanos
Carlos Llanos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Carlos Llanos

ASKER

See comment above.