Articles of get template part

using get_template_part() inside a widget and passing variables

I read that get_template_part() should only used by themes not plugins, I don’t know if using it inside a widget function (created by the theme) is considered as a plugin or not. Anyway, I’m trying to pass that widget variables ($myvar) to the template (‘loop.php’ in my case), but it doesn’t fetch it even with […]

Get_template_part seems to be ignoring my template

I am developing a website that requires specific pages to have certain elements change color in addition to a full-width calendar page. I figured that using page templates and changing what get_template_part looks for would be the simplest approach, but I’ve run into unexpected trouble. The page template loads fine, but the specific content template […]

Get_template_part() problem with the_content()

I am creating one page wordpress theme – i am new to wordpress dev. The one page website have sections which represents pages. So every section on front page is page created via admin panel. There is page.php and page-home. Front-page needs to display all pages as a sections. So I started with loop inside […]

Does get_template_part() content gets parsed if it's not executed?

My page templates are currently built up as shown in first example but I really don’t like that half of the template is just sitting there, not being used and takes the server resources for no good reason. Does everything in both examples gets parsed by server, emphasis on get_template_part()? <?php //Page template if( $something […]

get_template_directory() returns wrong address on VPS

I’m having the following problem with a WordPress installation on a VPS server. I’m trying to read from a JSON file but the returned address from get_template_directory() is wrong: $url = get_template_directory() . ‘/inc/includes/acf-fonticonpicker’; $json_file = trailingslashit($url) . ‘icons/selection.json’; if($wp_filesystem->exists($json_file)){ $json_content = $wp_filesystem->get_contents($json_file); } $json_file is empty because the JSON file is not found. The […]

Get template part with CPT and Custom Taxonomy conditionals

I have two Custom Post Types Video and Gallery and a Custom Taxonomy Status with the term Featured. Right now I’m showing these CPT in my index.php, but I want to style each of them, so I’m using get_template_part to achieve it. The problem comes when I want to get templates for an specific term […]

Get template part using a custom taxonomy term

I’ve been using the following code to get a template part based on the parent term. It was working fine until I updated WordPress to v4.4 earlier today. Since updating if there is also a child term selected it no longer works to bring in the template part. Any ideas? I’m tearing my hair out. […]

Both the require and add_template_part function are not including the file

I’m trying to add a require function in my functions.php, to include a file that is in the wp-content folder. I first tried this with the function content_url . ‘filename.php’So the line of code looked like this: require(content_url . ‘filename.php’. However this made the site crash, because of a die() probably. After that I tried […]

Passing variables to template parts

I have one template file videos.php which has the following line of code in it (aswell as a load of HTML): <?php get_template_part(‘loop’, ‘feed-videos’ ); ?> inside that template part, I have the following: <?php $video = ‘video-‘ . $post->ID; ?> <?php get_template_part( ‘include’, ‘modal-video’ ); ?> I would then like to be able to […]

Display post order ranking within wordpress loop

I am trying to display the numerical post order ranking on the home page, however, I am using template_parts and am not aware of how to do this when the html is separated from the wordpress loop. Here’s what I want to see: Here is my loop in index.php <div class=”most-recent-feed”> <?php if ( have_posts() […]