I am customizing my-account page of my theme. I have added a new endpoint and it works properly when calling the function “get_template_part()” with a template created with php.
However, I would like to load a template that I have created with Elementor. I have tried different things but I do not manage to find a solution.
Thanks for your help
]]>I’ve created a template-noheader.php page in a templates folder for my child theme with the comments at the top so it comes up as an option when I’m editing the page.
This seems to work, text I add on this page to test it appears on my site.
The problem is when I try to call the template part content-noheader.php within the template. I’ve based this off of the templates with the twentytwenty theme and plan to edit it. But text I put on this page doesn’t appear on my site.
File structure: templates/template-parts/content-noheader.php
I tried this first: get_template_part( ‘template-parts/content-noheader’);
But found that it didn’t display any of the content – so the page consisted of the site header and the footer.
When I was searching around for a solution I came across this syntax:
get_template_part( ‘template-parts/content’, ‘noheader’ );
At first I thought this had worked, but when I started to edit content-noheader.php the changes didn’t appear, so I think it is still pulling the parent theme’s default content file.
I’ve tried assigning the template to the about page as well just in case the the index.php in the parent theme was overriding. But it doesn’t work there either.
I know I’m probably missing something as I haven’t played around with page templates before. I’ve previously removed titles with css but I also don’t want the area it would appear in to be displayed at all and having a template that I could choose to use on other pages seemed to be a neat solution.
Any pointers would be appreciated.
]]>'order'=> 'ASC', 'orderby' => array( 'menu_order', 'parent' )
), although, when I test without the custom WP_Query (or even setting 'paged' => -1
, to attempt to show all posts) I still experience the same unwanted behavior:
Problem: Using load_template()
for a custom template part (e.g., content-{post-type}.php) only shows one (1) custom post on a given archive-{post-type}.php or taxonomy-{taxonomy}.php page instead of matching the queried pagination parameters.
Pagination “works,” insofar as the paged navigation links appear and function, but only one (1) post displays on a given archive/taxonomy page, so page “1” only displays my first post, page “2” only displays my “nth” post (where “n” is equal to
query_var( 'posts_per_archive_page' )
orquery_var( 'posts_per_page')
respectively).
Code: As I’ve been developing my plugin’s template files, I’ve been trying to follow WordPress codex recommendations by using load_template()
instead of working with get_template_part()
(as I would with a theme). However, this snippet appears to be the source of my problem:
`if ( $overridden_template = locate_template( ‘some-template.php’ ) ) {
/*
* locate_template() returns path to file.
* if either the child theme or the parent theme have overridden the template.
*/
load_template( $overridden_template );
} else {
/*
* If neither the child nor parent theme have overridden the template,
* we load the template from the ‘templates’ sub-directory of the directory this file is in.
*/
load_template( dirname( __FILE__ ) . ‘/templates/some-template.php’ );
}`
(Again, this snippet comes straight from the Codex.)
As a temporary workaround, I’ve been using get_template_part()
to load my theme’s template parts. However, this introduces an altogether different problem:
While all posts appear on all pages as expected, the theme’s ‘content.php’ file is loaded instead of my plugin’s custom ‘content-{post-type}.php’ (which is also expected, given how
get_template_part()
works with themes instead of plugins).
At least something “works” (two somethings, by that measure) but I want to be able to package my plugin to display my ‘content-{post-type}.php’ on archive and taxonomy pages as well as single pages.
That is, I have determined, perhaps falsely, that the problem is with my implementation of load_template()rather than with my particular <strong>'content-{post-type}.php'</strong> file because it works fine when using
load_template()` as the Codex prescribes within my custom <strong>’single-{post-type}.php'</strong> template.
I’ve read other places (e.g., on <a href=”https://wordpress.stackexchange.com/questions/94343/get-template-part-from-plugin” target=”_blank”>WordPress Development Stack Exchange</a>, which actually failed to load the template part at all for me) how get_template_part()
can be assimilated into plugins. However, this seems a bit too far afield, and I would really like to develop this functionality in keeping with WordPress’ recommendations for load_template()
, if at all possible.
I have a feeling my problem could have something to do with my implementation of pagination, but, as always, I’m just trying to follow <a href=”https://developer.www.ads-software.com/reference/classes/wp_query/#pagination-parameters” target=”_blank”>the Codex</a> by using: $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
.
I didn’t think my problem could be so unique, but I haven’t found any other forums or tutorials that cover this sort of (mis)functionality.
Thanks for your assistance.
]]><?php
if ( have_posts() ) : the_post();?>
<div> <?php get_template_part( 'page', 'shop' ); ?></div>
<?php endif; ?>
And code of page-shop.php
<div class="container-fluid "> <!-- play section -->
<div class="row">
<div class="col-xs-12 col-sm-2 col-md-2 col-lg-2">
<h2 class="" style="text-transform:uppercase"><?php the_field('shop_name');?></h2>
</div>
<div class="col-xs-12 col-sm-2 col-md-2 col-lg-2">
<h2 class="" style="text-transform:uppercase"><?php the_field('shop_category');?></h2>
</div>
<div class="col-xs-10 col-sm-10 col-md-7 col-lg-7 ">
<?php $image = get_field('shop_item1');
if( !empty($image) ): ?>
<img class=" img-responsive" src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif;?>
</div>
</div> <!-- row -->
</div>
]]><?php
get_header(); // Loads the header.php template
if (have_posts()) : ?>
<div id="blog-wrap" class="blog-wrap-wide blog-isotope clearfix">
<?php
// Loop through each post
while (have_posts()) : the_post();
get_template_part( 'content', get_post_format() );
endwhile;
?>
</div><!-- /post -->
<?php
wpex_pagination(); // Paginate your posts
endif;
get_footer(); //get template footer ?>
]]>I have created a custom post type called feature. I am using the get_template_part function to call the title and the content of this post type in my front-page.php. (“Feature” is basically one of the 3 service highlights on the front page of the website mentioned above)
I want these features arranged into 3 list items that are horizontally aligned just like the above website. Each list item contains a div that holds the h2 and p tag for the heading and content respectively. The UL sits inside an article.
Currently I have been able to achieve the layout I wanted, but when inspecting the code with chrome tools, I see several things that are off. First of all, instead of getting 3 LIs inside one UL, I have the parent article being repeated 3 times resulting in 3 ULs with only 1 LI in each. It LOOKS the same on the web, but it presents issues. The parent elements no longer wrap the children as they did before (prior to implementing this structure in the php files, I placed the html in the wordpress admin area and used get_content(); and it all worked.) I am using the exact same stylesheet with no changes so I expected things to look the same, but I cannot apply the background color to the article now because it doesn’t wrap the children.
In addition there are empty p tags before and after the actual p tag that holds the post type content.
Thank you for the help current code is below.
front-page.php
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<h1><?php the_title();?></h1>
<?php
$args = array(
'post_type' => 'feature',
'posts_per_page' => 3
);
$loop = new WP_Query($args);
if ( $loop -> have_posts() ) :
/* Start the Loop */
while ( $loop -> have_posts() ) : $loop -> the_post();
/*
* Include the Post-Format-specific template for the content.
* If you want to override this in a child theme, then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
//get_template_part( 'template-parts/content', get_post_format() );
?>
<?php get_template_part( 'template-parts/content', 'feature' );
?>
<?php
endwhile;
//the_posts_navigation();
else :
//get_template_part( 'template-parts/content', 'none' );
endif; ?>
</main><!-- #main -->
</div><!-- #primary -->
content-feature.php
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<ul>
<li>
<div>
<h2><?php the_title(); ?></h2>
<p><?php the_content(); ?></p>
</div>
</li>
</ul>
</article><!-- #post-## -->
style.css
#page{
background-image: url('../../../wp-includes/images/mainImage.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
height: 100vh;
margin: 0;
}
#content{
margin:0 auto;
max-width:980px;
}
#primary{
max-width: 742px;
margin: auto 72px auto auto;
}
main h1{
text-align: center;
color: white;
font-weight: bold;
}
main ul li{
list-style: none;
max-width: 215px;
display: inline-block;
text-align: left;
margin: 0 10px;
line-height: 100%;
color: #26729B;
float:left;
}
main ul li p{
font-family:Arial;
font-size: 14px;
}
main ul li h2{
line-height: 120%;
font-weight: bold;
font-size: 1.6em;
}
main ul{
text-align: center;
padding: 0px;
margin: 0 auto;
}
main > div > p{
text-align: center;
padding:0px 0px 15px 0px;
margin:0px;
color: #434A52;
font-size: 36px;
}
main > article {
background-color: rgba(255, 255, 255, 0.66);
padding:0px;
}
]]>Problem I found with this, it does not order the template parts ones imported to the Parent page! Please, is there someone that could help solve this?
I will copy over part of the original post and replace it with my code:
…create a Child page with a custom page template create another (content) template as well. You could put the whole loop in there or only the part that’s inside the loop. For example for a child page with a custom page template filename (layout_1col_visualeditor.php) create a template file (layout_content-layout_1col_visualeditor.php).
And on the custom page template (layout_1col_visualeditor.php) include the file like so:
<?php
/*
* Template Name: Child Page - Layout 1col Visual Editor
*/
?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'layout_content', 'layout_1col_visualeditor' ); ?>
<?php endwhile;?>
Now you can include the get_template_part on the Parent page (layout_loader-page.php) like so:
<?php
/**
* Template Name: Parent Page - Section Layout Loader
*/
?>
<?php get_header(); ?>
<!-- CONTENT WRAPPER -->
<div id="content_wrapper" class="single_pages clearfix">
<?php
global $wp_query;
// is Page a parent page
if ( $post->post_parent == 0 ) {
// on a parent page, get child pages
$pages = get_pages( 'hierarchical=0&parent=' . $post->ID );
// loop through child pages
foreach ( $pages as $post ){
setup_postdata( $post );
// get the template name for the child page
$template_name = get_post_meta( $post->ID, '_wp_page_template', true );
$template_name = ( 'layout_loader' == $template_name ) ? 'page.php' : $template_name;
// default page template_part content-page.php
$slug = 'page';
// check if the slug exists for the child page
if ( locate_template( 'layout_content-' . basename( $template_name ) , $load, $require_once ) != '' ) {
$slug = pathinfo( $template_name, PATHINFO_FILENAME);
}
// load the content template for the child page
get_template_part( 'layout_content', $slug );
}
}
?>
</div>
<!-- END CONTENT WRAPPER -->
</div>
<!-- END MAIN WRAPPER -->
<?php get_footer(); ?>
And just in case, I copy also the code for the included child page (layout_content-layout_1col_visualeditor.php):
<section class="visualeditor">
<!-- content block -->
<main>
<article class="clearfix">
<h2><?php the_title(); ?></h2>
<div><?php the_content(); ?></div>
</article>
</main>
<!-- end content block -->
</section>
Thanks for your help in advance!
[please do not bump]
]]>