Page attribute, template, in a wordpress "project"

Asked

Viewed 591 times

0

I have a site in Wordpress, of which some pages I use instead of the wordpress editor, file .php with a Template Name, in such a way I point out in wordpress the template, located in the page attributes.

However on this site, I also use the "projects" part to create the portfolio, in general all follow a basic pattern mounted directly on wordpress with the assembler divi, however some specific projects is a little more worked the page, one of them do several things in php even, css animations, js, svg, among other things. I put together a preview of the page already in a . php file with a template name, but I realized that for projects it does not have this tab Atributos da Página.

Is there any way to make a specific project pick up a. php file instead of just being mounted directly in the wordpress editor?

Thank you.

  • You want to run a '.php' file any outside of WP logic, that’s it?

  • @Caiofelipepera I have a php file, which I import the header get_header(); and the footer, with a template name. Because I run several direct conditions in php, user level of which I consult an external wordpress base. With pages beauty, I do it already, but with the "projects" I did not find this option, and I do not know if there is any way.

  • @Caiofelipepera know that mt is not well in the "wordpress patterns" haha but this project is in this first version with a lot of "patched" stuff in pure gambiarra for timing reasons, etc.. and as soon as releasing this version will already begin to be developed in a descending way a v2. then if there is a way even that goHorse I am accepting. haha

  • But what are "projects"? What is a "Divi" assembler? Your question is very confusing... in that reply I talk about something that MAYBE can help you, but I don’t know...

  • The "projects" is a wordpress portfolio plugin. project image. the Divi builder is also a plugin that came along with the theme q I use, serves to facilitate page creation, image of the builder. Now when I edit a normal page, there is the "page attribute" menu from which I can select the template as in this image

  • but when I edit a project, there is no such attribute tab, from which I can select the template. as in this image

  • in the upper right corner there is an icon called "screen options". click on it

  • @Caiofelipepereira there is the option of attributes, it works as a post the projects, is there any way to make a post catch php? or the only output will be that plugin? @.@

Show 3 more comments

1 answer

1


The "Page Attributes" box only exists for hierarchical Post Types, and your Projects should not be.

In this case you can rename the PHP file and change the Templates Hierarchy in your favor.

Example: if the project URL is example.com/project/project-name, you can do:

add_filter( 'template_include', 'redireciona_projeto' );
function redireciona_projeto( $template ) {
    global $post;
    if ( 'nome-do-projeto' == $post->post_name ) {
        $novotemplate = locate_template( array( 'nome-do-arquivo.php' ) );
        if ( '' != $novotemplate ) {
            return $novotemplate ;
        }
    }
    return $template;
}
  • Man, thanks a lot, this solved my problem! I didn’t know about this filter template_include. perfect! only change I needed to make was to change $post->slug for $post->post_name to catch the Slug correctly. Thank you again! :D

  • 1

    Opa, thanks. I wavered with the name of the property, already edited to correct.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.