1
votes

I am a beginner programmer and I got little problem.

The problem is that I can't link Custom page (page-product-all.twig) to Wordpress admin (can't find page-product-all on Wordpress admin.)

  1. I have created custom twig page (page-product-all.twig)
  2. I have created custom php file (page-product-all.php)
  3. I have created a page in Wordpress admin panel (Page Product All)

But when I change the page on Admin (Page Product All), the page (page-product-all.twig) does not change.

Thanks in advance!

1
Could you post the code from the both page-product-all.php and page-product-all.twig, will be a lot easier to help out that way – Alex Baulch

1 Answers

1
votes

Take a look at page.php from the Timber Starter Theme:

<?php

$context = Timber::get_context();
$post = new TimberPost();
$context['post'] = $post;
Timber::render( array( 'page-' . $post->post_name . '.twig', 'page.twig' ), $context );

The Timber::render method on the last line loads page.twig as the default page template. However, Timber also checks for any twig files with the page- prefix followed by the name of a post (or in this case a page) with the code:

'page-' . $post->post_name . '.twig' 

I really like this technique for handling custom pages because it prevents us from having to create custom page php files. This is especially helpful on sites with many pages.

If you want the page title to be "Page Product All" then your twig file will have to be page-page-product-all.twig. I sort of have a feeling you just want the page to be called "Product All" so in that case the twig file would remain page-product-all.twig and you will have to create a page called "Product All"

Now add a simple <h1>hello world</h1> to page-product-all.twig (I prefer <h1>hi mom!</h1>), preview the Product All page and voila. Custom page templates with Timber.