How to make an archive page displaying posts in a date range

Saving the date in post meta is a slightly more sane approach, the post_date column was not designed with your use case in mind. You may get weird results with dates before the Unix epoch (January 1, 1970). Then it’s just a simple meta_query to load posts between dates, no filter necessary. $start=”1900-01-01″; $end = … Read more

Grabbing the page template name?

An alternative to @Ben Cole that’s less intensive (especially if you have several page templates), but not as awesome because it doesn’t use the WP_Theme object 😉 function wpse_184317_get_template_name( $page_id = null ) { if ( ! $template = get_page_template_slug( $page_id ) ) return; if ( ! $file = locate_template( $template ) ) return; $data … Read more

Adding variable to get_template_part

It looks like you’re just trying to concatenate a string, so it can be done like this: <?php get_template_part( ‘template-parts/component-page/component-‘ . $variable ); ?> Or you could use string interpolation (note the double quotes used here): <?php get_template_part( “template-parts/component-page/component-{$variable}” ); ?> Alternatively, get_template_part() can take two parameters, $slug and $name: <?php get_template_part( ‘template-parts/component-page/component’, $variable ); … Read more

Loading page template into shortcode

get_template_part takes slug as first parameter and not filename. So it should be: get_template_part( ‘template-sponsors’ ); And with more details… This function takes two parameters: get_template_part( string $slug, string $name = null ) And inside of it, the name of a file is built like this: if ( ” !== $name )         $templates[] = “{$slug}-{$name}.php”;       $templates[] = “{$slug}.php”; So, … Read more

Custom template for each page

there are a few way you can do that: Template Hierarchy – each page with is own theme file using page-{ID/slug}.php Custom Page Templates – Individual Pages can be set to use a specific custom Page Template from the edit screen. but if you are just looking to change whats on the sidebar then there … Read more

Confused on AJAX submit form through page template

<form action=”<?php echo get_template_directory_uri() . “/validation.php”; ?>” id=”contactForm”> 😱 So I’ll outline the basic fundamentals, so you have a framework to move forwards with Fixing Admin AJAX So I’ll cover this very briefly as it’s not the crux of my answer, but would be useful: Add a hidden input field named action rather than adding … Read more