public function add($template, $title, $content = '')
{
if (is_admin()) {
$tpl = plugin_dir_path(__DIR__) . "templates/{$template}.php";
if (file_exists($tpl)) {
add_filter('page_template', array($this, 'set_template'), 10, 2, $tpl);
}
$this->pages[] = [
'post_title' => $title,
'post_type' => 'page',
'page_template' => $template.".php",
'post_status' => 'publish',
'post_name' => $this->slug_gen($title),
'post_content' => $content,
'post_author' => get_current_user_id()
];
}
}
public function run()
{
if (is_admin()){
foreach ($this->pages as $page){
if(!isset(get_page_by_title($page['post_title'])->ID) && !$this->slug_exists($page['post_name'])){
$page_id = wp_insert_post($page);
}
}
}
}
public function set_template($page_template, $tpl)
{
$page_template = $tpl;
return $page_template;
}
Poderiam me ajudar a identificar o que estou fazendo de errado
]]>since many years I′m using the XMLRPC API to create new Posts from my own Dashboard. However, since some weeks the parameter “page_template” which refers to “wp_page_template” in the Doc is not longer working.
Since newPost works with every Parameter that wp_insert_post accepts (function hasn′t been changed since 4.4 as of the changelog) and it is still supported I have no clue whats going on.
I′m using the parameters for newPost like this for many years:
$wp_params = array(
'post_title' => 'Title',
'post_content' => '',
'post_status' => 'draft',
'page_template' => 'page-product.php',
'post_date' => date('Y').'-'.date('m').'-'.date('d').' '.date('i').':'.date('i').':'.date('s'),
'post_name' => 'test',
'post_parent' => '',
);
Does anyone know what has changed?
]]>I have created the “template-pagename.php” and it’s corresponding “template-pagename.twig”.
In the header.twig, I have the UberMenu function as {{ fn(‘ubermenu’, ‘main’) }}
I would like to specify it to use this “main” menu for all pages and then display a different UberMenu for any page that is assigned to a my new page template.
Traditionally in WP I would use “is_page_template” and setup if/else statements. What is the correct way to do this with Twig?
https://www.ads-software.com/plugins/timber-library/
]]>Here is an example from wp-admin/includes/meta-boxes.php, line 583:
if ( 'page' == $post->post_type && 0 != count( get_page_templates() ) ) {
If this is changed to something like this:
$ct = get_post_type_object($post->post_type)->capability_type;
if ( 'page' == $ct && 0 != count( get_page_templates() ) ) {
then the page template attributes will not only displayed for the built-in page types, but for the custom types built on it aswell. Other lines which could/should be changed: wp-admin/includes/post.php line 479 and wp-includes/post.php line 2636.
Is there a reason why the page template attribute is only allowed for the built-in page type? Could these changes be implemented into WordPress?
]]>get_header();
$ancs=get_post_ancestors($post->ID);
$parent=getPostParent($post->ID);
if ( (isDest($post->ID)!=0) || (isDest($parent)!=0) || (in_array(29, $ancs))){
$dest=true;
//echo "2dest</br>";
}else{
if (in_array(6292, $ancs) || $post->ID==6292){
$span=true;
}else{
//$dest=true;
//include("sideComBoxes.php");
}
}
Code critique aside..I was just wondering how I could execute this code from a WP Filter or Action when the page.php template is run?
I looked into a few Filters such as :
template
applied to the template returned by the get_template function.
So basically I would need a filter to add to the “template” hook and create a function with a conditional statement that will execute code only for a specific template?
I understand the logistics. But Will this work and what object will I need from the global wordpress variables to see the template?
]]>However, I’ve not been able to do this successfully.
I want to use a custom theme page (page-proposal.php) in the theme directory properly named as “Page Proposal”. My custom form uses wp_insert_post as follows (in part):
$prop_page = array();
…
$prop_page[‘page_template’] = ‘page-proposal.php’;
…
wp_insert_post($prop_page);
Though everything else in the array goes through fine, the new page’s template ends up as “default”. I checked the db and found the entries in the wp_postmeta table ending up as
_wp_page_template default
When I change the template through the GUI everything’s OK, and the db updates properly. This makes me think that my wp_insert_post() isn’t sending the page_template value to the right place.
Ideas?
]]>