Tag Info

Hot answers tagged

5

Custom implementation vs. Standard API usage Using the WP AJAX API is the way to go. First off, you get access to the complete set of WP APIs, you can leverage standard jQuery $.ajax() and similar API calls and you are running standard conform, gaining access to all knowledge spread around the web with articles or for e.g. in answers on this site. In the ...


4

WordPress 3.9 introduces a theme_page_templates filter. The example below from a Twenty Fourteen child theme functions.php shows how to remove the "Contributor Page" template: function tfc_remove_page_templates( $templates ) { unset( $templates['page-templates/contributors.php'] ); return $templates; } add_filter( 'theme_page_templates', ...


3

WooCommerce questions are off-topic, but since reviews are merely comments, I think we can make the case that ordering comments is still on-topic. wp_list_comments() has a reverse_top_level parameter that will set the most recent comment first and then go backwards. Assuming it works like I think it should then you'd want to add this parameter to ...


3

If you have a look at the template hierarchy, custom post types are usually displayed on archive templates. Normal template hierarchy does not make provision for page.php type templates to be used to display custom post types by default. The problem with archive templates is that they don't automatically get added to the default nav menu, and creating a ...


3

Yes, this is the intended behaviour: page-{slug}.php - If the page slug is recent-news, WordPress will look to use page-recent-news.php So, simply use a different filename for your templates, like template-contact.php for example. You can find more info about this here: https://codex.wordpress.org/Template_Hierarchy


3

This is an add on to @kaiser answer, read that before. To be honest wp_localize_script, add_action are the best part of Ajax API, and really, they are an help, not a problem. Let's imagine you have 120 ajax functions. Even if you don't use admin-ajax.php see again your workflow: Check user is authenticated, if not, return a 403 header and exit(); ...


3

You haven't created a query to return your post index results. Let me back up... In WordPress something called the "Main" query runs very early in the page load, and well before your template files load. That query retrieves the posts to display and also (more or less) determines which template file to use to display the results. That "Main" query ...


2

First check that there isn't a page set as a front page in "Reading Setting". If that is set, index.php is not used as the home page, but the template of the page you set as front page. In that case, you need to find that template and add you conditional is there. <?php if(is_user_logged_in()) { get_header(); ?> <div id="primary" ...


2

You forgot to end the if statement. this should work: <div id="primary" class="site-content"> <div id="content" role="main"> <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( 'content', 'page' ); ?> <?php if (is_user_logged_in()): echo '<form ...


1

You might wanna take a look at this: https://codex.wordpress.org/Template_Hierarchy Your index.php is typically the last file that Wordpress will look for when loading any page. In the case of the homepage, it will first look for front-page.php then home.php (if your home page is set to show latest posts, and not a static page). If you're changing the ...


1

I wouldn't use custom page templates merely for changing the layout of the blog posts index. Using page templates for the blog posts index bypasses the core handling for display of the blog posts index (which per the template hierarchy uses either home.php or index.php to render). Edit I never...said that I want to change layout of the blog posts ...


1

You can certainly set up a page template for custom post types. Give this a whirl: <?php /* Template Name: Your template name */ // Get header get_header(); ?> <div id="primary"> <?php // Query post type $the_query = new WP_Query( array( 'post_type' => 'cpt_name', 'posts_per_page' => -1 ) ); if ( $the_query->have_posts() ) : ?> ...



Only top voted, non community-wiki answers of a minimum length are eligible