wordpress - Timber use different template for custom post type -
i new php, wordpress , timber. have custom post type called projects, uses posts archive template , going crazy create specific projects archive template can have different layout it.
this index.twig looks
{% extends "layouts/base.twig" %} {% block content %} <div class="uk-child-width-1-3@m" uk-grid uk-scrollspy="cls: uk-animation-fade; target: > div > .uk-card; delay: 500; repeat: false"> {% post in posts %} {% include "tease-post.twig" %} {% endfor %} </div> {% endblock %}
and tease-post.twig
{% block content %} <div> <div class="uk-card uk-card-default"> <div class="uk-card-media-top"> <a href="{{post.link}}"><img src="{{post.thumbnail.src('full')}}" alt=""></a> </div> <div class="uk-card-body"> <h3 class="uk-card-title"><a href="{{post.link}}" class="uk-button uk-button-text">{{post.title}}</a></h3> <p>{{post.get_preview(25,false,false,true)}}</p> </div> <div class="uk-card-footer"> <a href="{{post.link}}" class="uk-button uk-button-text">read more</a> </div> </div> </div> {% endblock %}
any idea how works? can't find related documentation..
there few diff't methods depending on you're looking achieve. seem simplest is...
{% extends "layouts/base.twig" %} {% block content %} <div class="uk-child-width-1-3@m" uk-grid uk-scrollspy="cls: uk-animation-fade; target: > div > .uk-card; delay: 500; repeat: false"> {% post in posts %} {% include "tease-'~ post.type ~'.twig" %} {% endfor %} </div> {% endblock %}
you create file called tease-project.twig
(assuming `project name of custom post type's slug) might this...
{# tease-project.twig #} <h2>my cool project is... {{ post.title }}</h2>
if you're looking special cpt's specific archive page...
check archive.php
file, if you're using starter theme should load file called archive-projects.twig
(assuming projects
name of custom post type).
the logic customizable can load .twig
files want depending on circumstance
Comments
Post a Comment