Tag Info

New answers tagged

0

Sorry I was using wrong structure, after looking through a bit more i found out exact difference for CPT and cutom taxonomies. For custom post types the template structure is like:-\ single-{post-type}.php archive-{post-type}.php search.php index.php And for Custom taxonomies, the template structure I found out from here:- Link:-Templates for Custom Post ...


0

I used the following functions to solve this problem. //This adds a custom query variable to the permalink function add_custom_query_var( $vars ){ $vars[] = "shop_name"; return $vars; } add_filter( 'query_vars', 'add_custom_query_var' ); function add_rewrite_rules($aRules) { $aNewRules = array('shop/([^/]+)/?$' => ...


1

Using is_page(8) will make your code a bit static. Let's make it dynamic as you're after with is_page_template(): <?php function prefix_conditional_body_class( $classes ) { if( is_page_template('mytemplate.php') ) $classes[] = 'mytemplate'; return $classes; } add_filter( 'body_class', 'prefix_conditional_body_class' ); Worked for me in ...


0

Use template_include in your functions file with a conditional tag. add_filter( 'template_include', 'default_page_template', 99 ); function default_page_template( $template ) { if ( is_singular( 'page' ) ) { $default_template = locate_template( array( 'default-page-template.php' ) ); if ( '' != $default_template ) { return ...


0

I have not tested this, but it may work. The template is chosen based on a value in the global post object, so we need to change that value in the post object before the metabox is rendered. The code which chooses the default dropdown is here: https://core.trac.wordpress.org/browser/trunk/src/wp-admin/includes/meta-boxes.php#L751 ...


1

On request, a custom template does not mean custom query :-). As already mentioned, NEVER use query_posts, it breaks the main query object and page functionality, one of which is pagination. Many plugins and functions relies on the main query object, you break that, you break those functions as well. As this is a custom category template, it is also not ...


1

Simple solution, use get_template_part(). For example: get_template_part( 'partials/footer' ); Which would get the footer.php inside the partials/ directory. Another example: get_template_part( 'partials/footer', 'home' ); Which would get the footer-home.php inside the partials/ directory. One more example: get_template_part( ...


0

... from a custom Wordpress page template to my child theme functions.php file... You can't. And a global variable won't help. The theme's functions.php file loads first, before any other templates load. You can't pass variables backwards to something that has already loaded. What I think you want to do, based on what your code appears to be trying ...


0

Try this : https://wordpress.org/plugins/display-template-name/ It's my plugin. It display the current template file + other include files within the current


0

Ok, an answer to all. First, thank you for you help. Anyway, none of your solutions really address my issue. I don't like custom links on nav menus, at all. And that's because they're not dynamic, you cannot build them dynamically. So when you move the site and change url (for example, from staging to production) you'll have to remember to manually change ...


1

Update You can make use of the add_rewrite_endpoint: add_rewrite_endpoint( 'schools', EP_PERMALINK | EP_PAGES ); You can then check in the sidebar for the schools variable: global $wp_query; if ( isset( $wp_query->query_vars['schools'] ) ) { // ... } What is worth mentioning is that your URL will look like ...


0

Just create an archive-{post_type}.php when you create a custom post type and include this function: flush_rewrite_rules(); Make a page of your custom post type. It's called an archive page.


2

Custom post type archive page does not need "dumb" Page. In fact, there could be the culprit. You should try this: Remove /* Template Name: Staff */ from archive-staff_member.php (not needed) Remove "dumb" stuff Page (if created). There could be some permalink conflict. Go to Admin > Settings > Permalinks and re-save it (it will regenerate rewrite rules) ...


0

Yes, the function is_post_type_archive only works in archive.php To have an item on nav menu links to your staff_member, you will add a custom link menu item in stead of a page whose template is your file tempate. The URL of that item will be got when you vardump this: get_post_type_archive_link('staff_member') And to custom the performance of the ...


-1

First create on page named as Items as your wish which display the content from items post types, than create one template file as below and named that template-items. Select that template for the page you have created. <div class="container"> <div class="row"> <div class="col-md-9"> <div class="panel ...


0

The simplest solution: echo get_the_category_list( ', ' ); Following your way: Change your $args like so: $args = array( 'template' => '%2$l', 'term_template' => '%2$s', ); And then, add this to your functions.php file (this will affect all %l markers!); add_filter( 'wp_sprintf_l', function($templates) { // ...


1

I assume you would like to end up with something like this: Theme way If you want to put this logic in your template, as you state in your question, there is quite a bit of coding. You need to: create metabox create content (field and description) in that metabox - that's called "callback" in the meta_box docs create logic that saves data from the ...



Top 50 recent answers are included