Questions tagged [templates]

Within the context of WordPress Theme-ing, the term 'template' refers to PHP files used to display content.

Filter by
Sorted by
Tagged with
3 votes
1 answer
5k views

How to hide/redirect the author page

I have a website where I let people subscribe. I would like to only show the author page for actual authors who have written a post. I wrote this code that checks for post the problem is I can't use a ...
Brooke.'s user avatar
  • 3,893
3 votes
2 answers
3k views

Load different template file when condition met?

If I visit a page on my WordPress site, WP goes and determines what template file it should use based on the template hierarchy. If I'm doing some logic checking in the hook init and say my ...
Scott's user avatar
  • 12.2k
3 votes
3 answers
9k views

How to list/show all custom post types regardless of category?

I realise with this question I was overcomplicating a really simple issue. My question is really this: How to have a page listing all items of a given custom post type? Say the custom post type ...
hawbsl's user avatar
  • 500
3 votes
1 answer
2k views

Custom taxonomies, with custom rewrites/slug, AND loading a taxonomy archive template from a plugin

I think maybe my understanding about rewrites and templates for custom taxonomies and CPTs is wrong and maybe someone here could help me solve my problem and educate me. So I have a post type, "...
rugbert's user avatar
  • 168
3 votes
4 answers
23k views

Apply template to custom post type

Today I got a client that wanted custom template for each page and section within. I proposed Laravel custom sh3t, but he wanted WordPress, as it seems more easy to main( not from my experience ). .. ...
Dimitrov's user avatar
3 votes
1 answer
10k views

Change the output for [gallery] shortcode

I'm sorry if this question was answered here, but I couldn't find it. Is possible to change the HTML output of [gallery] shortcode (without plugins)? I would like to show the thumbnails as another ...
gregolin's user avatar
3 votes
1 answer
95 views

What is best way passing variables to theme templates and using them different places like widgets?

I have a template file at /parts/template.php which contains a post listing code like, echo get_the_title(); //same lines with my_render_function and i am using it at archive.php with this lines. ...
Ajna Sarut's user avatar
3 votes
1 answer
27k views

How to customize search result page title?

I would like to customize the page title of the search result page: from: <title>Search Results for “search string” – Page 2 – Sitename</title> to: <title>“search string” result ...
KDX's user avatar
  • 183
3 votes
2 answers
3k views

Custom Post Type Archive URL takes over page URL

I am having troubles with the archives for a custom post type. I have a WordPress page at /address/ I have created dynamic custom posts that are to appear at /address/post#/ When I activate this ...
Cyrus's user avatar
  • 29
2 votes
1 answer
450 views

Create separate template for shared custom taxonomy with shared terms

I have created custom taxonomy called "product_category", it has been shared with post type "books" and "movies" . So I need to create a different template for both post ...
user2506619's user avatar
2 votes
1 answer
13k views

How to assign a class to a page with a custom template?

I tried with the bellow code to assign a body class to a page with a custom template, but this didn't work. What is wrong here? function prefix_conditional_body_class($classes) { if ( ...
Yuri's user avatar
  • 1,111
2 votes
2 answers
5k views

When calling wp_title(), do you have to create some kind of "title.php" file?

... or does wp_title() already handle the various contexts in your blog? This could clarify for me how I can achieve a reusable index.php file without having all the conditional statements inside it ...
chamberlainpi's user avatar
2 votes
4 answers
3k views

Grid layout "last" class to every third item

Seems like a trivial problem but I can't get it to work. I need to add class="last" to every third post. Here is my code: <?php $count = 0; $my_query = new WP_Query('cat=-18,-7&...
Eeyore's user avatar
  • 337
2 votes
2 answers
329 views

How do I create new content pages for my Custom Post Type?

I am using Underscores starter theme and I've created a custom post type video. $args = array( 'label' => __( 'Video', 'text_domain' ), 'description' => __( '...
Halnex's user avatar
  • 133
2 votes
3 answers
3k views

wordpress - load a template based on the URI

I have a number of custom of post types - i.e. 'windows', 'doors', 'garages' and I want to load a custom template (special.php) whenever my wordpress site has a url that looks like this: www.mysite....
Mazatec's user avatar
  • 1,026
2 votes
2 answers
548 views

TwentyTen: Overloading template.php files vs. get_template_part

I'm studying TwentyTen, under the assumption that it contains the best practices for writing themes and modifying them using child themes. I'm noticing what looks like a really redundant practice, ...
Tom Auger's user avatar
  • 7,046
2 votes
4 answers
5k views

WordPress as Backend, Laravel Front End: How to connect Routes?

I am going design a site and I though about using wordpress for it as the clients want to be able to edit the content and they are not very up to date with the latest technologies, so I though that as ...
Alvaro's user avatar
  • 131
2 votes
1 answer
3k views

How do I set a specific template for sub-categories?

There's a few posts about getting sub-categories to use the same template as their parent but I want to do something slightly different. I have a category 67, and I want all sub-categories of 67 to ...
Mikedefieslife's user avatar
2 votes
2 answers
1k views

A shared custom taxonomy between two custom post types

I have two custom post types: event and contact: http://acicafoc.josoroma.com/contactenos http://acicafoc.josoroma.com/eventos Both of them uses a custom taxonomy: country I just created a ...
José Pablo Orozco Marín's user avatar
2 votes
1 answer
155 views

Returning Variables back into a template

If I put a function that I want to use in a template I can put it into functions.php function myfunction(){ echo 'My String'; } add_action('myfunction','myfunction'); and in a template file put: ...
Jenski's user avatar
  • 127
2 votes
1 answer
114 views

How Can I Have A URL Changed Based on the Originating URL?

This is a followup to my question, "How can I have two different urls for the same page that load two different templates?" Assuming I implement Milo's answer (registering a new rewrite endpoint, ...
davemackey's user avatar
2 votes
2 answers
7k views

Problem getting single_template filter to work - I want to serve a different single.php file for posts in a certain category

I am trying to customize the behavior of my blog to serve a specific single post template based on the category the post is assigned to. I came across this filter in my parent theme which is what ...
Evan Mattson's user avatar
2 votes
2 answers
3k views

Post formats template

I would like to know what template wordpress uses to display post formats archive pages? What is parent template file that is used when there is no specified template file and what is specified ...
vlad's user avatar
  • 131
2 votes
1 answer
395 views

Sharing templates with the JSON API?

Is there any way to share 'templates' between JS and Wordpress? For instance, this sort of modest seat-of-the-pants templating feels ok: var AJAXSuccessFunc = function(data){ // calling this on ajax....
djb's user avatar
  • 2,250
1 vote
2 answers
4k views

Can not Remove Archives and Meta from Sidebar

This should be easy right? Removing Archives and Meta from the sidebars of two of my main WP pages. I can't seem to! I've looked in Appearance > Widgets and made sure Archives and Meta was not ...
Jessica's user avatar
  • 11
1 vote
3 answers
1k views

Accessing $post variable from template part

Here is a section of code that I have in a template file — to display sub-navigation if the page has child-pages: <?php // display sub-nav if page has children ?> <?php $children = get_pages(...
user avatar
1 vote
1 answer
26 views

Exclude a category from the filed under list only on some templates

this is a follow up question to this post Exclude a category from the filed under list The solution given works for me. However, I'm curious how I can get this to work conditionally? Specifically, ...
joycegrace's user avatar
1 vote
1 answer
3k views

Proper way to use get_the_content() in front-page.php and the content-home.php?

<div class="class1"> <ul> <li> <div class="class2"> <?php the_post_thumbnail( 'large') ?> </div> <...
WordCent's user avatar
  • 1,867
1 vote
1 answer
563 views

How to loop over custom fields in a page template?

I was originally using a single field and things worked perfectly with the following code. Now I need to alter it to loop of several fields that are similar. To start: I've created several custom ...
o_O's user avatar
  • 279
1 vote
3 answers
1k views

How to Handle CSS for Multiple Header header.php Files?

So, I'm building a new theme based on Underscores. So far, I've managed to get ACF Pro to call different header files from a dropdwon selction in the Options page but, now I am faced with the task of ...
AlonsoF1's user avatar
1 vote
3 answers
3k views

How to load different CSS in different Header?

I have two different files for the header in my theme. These are header.php and header-full.php. How can I load different CSS in different headers? I enqueue my CSS files in function.php like this:
felix felix's user avatar
1 vote
1 answer
267 views

How to include template according to meta post value

I'm trying to include a particular template according to the meta value stored for example: If the post meta value is value1, I want to include different template and if it's value2, I want to ...
Ashish Pariyani's user avatar
1 vote
1 answer
2k views

Custom page type - template under page attributes?

I thought we can apply templates to custom page types: You can't apply templates to custom post types in this manner. That will show up only if the post type is 'page' My code: function ...
Run's user avatar
  • 331
1 vote
2 answers
685 views

Adjust the results quantity for Search Results page pagination

I'm trying to override the number of posts to show on pagination for my search.php template, to be 16 vs 4. In the Reading settings on the back end, it is set to 4, which is desired because my front ...
Devon's user avatar
  • 35
1 vote
0 answers
33 views

Selecting An image from the Media LIbrary on the frontend

I'm using Wordpress to create a research tool where archival documents are transcribed into a relational database. Part of this is a transcription interface, a custom page. What I'm trying to do (...
Sam McLean's user avatar
1 vote
1 answer
31k views

Creating a custom category page with pagination

The past week I've been trying to figure it out on creating a custom category page with pagination. I've tried in so many ways but I cant get the pagination right. If anyone of you can help. What I ...
Puni's user avatar
  • 161
1 vote
2 answers
3k views

Template tags to display custom post type posts in category template?

I am developing a custom theme with custom post types involved. Custom post types have been defined via plugin 'Pods' (http://pods.io). When writing a category.php, I realized, that the standard loop ...
Bunjip's user avatar
  • 371
1 vote
1 answer
837 views

Is it possible to set a page template on a dynamic home page (articles list)?

When we create or edit a page, we can often set a page template depending of the used theme. Let say we have a "default" and a "with sidebar" templates. My home page is a list of the last articles, ...
Gaston Flanchard's user avatar
1 vote
2 answers
3k views

Create Pages from Database

i've recently decided to create a website with wordpress. My goal is to a visualize data stored in a MySQL database. Each id in the database should represent one page on the website. From what i've ...
QUE's user avatar
  • 11
1 vote
1 answer
1k views

Custom url structure for custom template

I have a custom taxonomy called activities and a custom role called operator. So, if example.com/operators/bird-watching is visited then I want to list all the operators that offers bird-watching. ...
saurav.rox's user avatar
1 vote
1 answer
748 views

Display different gutenberg template from selected post attributes

According to https://developer.wordpress.org/block-editor/developers/block-api/block-templates/, I have managed to add a template to the custom post type with the following code - /** * Portfolio ...
Cyrus Liew's user avatar
1 vote
1 answer
241 views

Use touch_time() on front-end form via plugin

I'm working on a plug-in that let people create posts from front-end form. I want to add date&time fields in the form using touch_time() but don't know how to use it on front-end. I have <div ...
Ohsik's user avatar
  • 407
1 vote
1 answer
1k views

Why is custom template not seen as page with is_page()?

I created a couple of templates for a project, which is in fact a child theme of the Contrast theme. In the Wordpress CMS, I can select the templates I created: https://i.stack.imgur.com/6OLaz.png (...
jansensan's user avatar
  • 183
1 vote
1 answer
54 views

Can I obtain differents links for different installed theme?

I have to show 3 differents template to a person and then say to him: "Please, choose one of these templates and I will use it for your web site" So the question is: Have I to install 3 differents WP ...
AndreaNobili's user avatar
1 vote
3 answers
733 views

Single page theme

I am trying to create single page theme. What i have trouble with is understanding this whole wordpress query logic. There is query object and supposedly i get all published posts like this: $...
Zayatzz's user avatar
  • 139
1 vote
2 answers
5k views

index.php template is used instead of blog page

I am trying to set WordPress so that home page is static, and the blog page is a separate page. So, I created two page templates in my theme., lets call them home_template and blog_template. Then, I ...
Greeso's user avatar
  • 2,166
1 vote
1 answer
626 views

On Taxonomy Template page, want to add Post_Type

I have a custom taxonomy template page in my theme. Essentially, when someone clicks on a term link into this taxonomy, I -ALWAYS- want to add a specific post-type to the query. I'm not entirely ...
Sam K's user avatar
  • 388
1 vote
3 answers
3k views

Best approach for loading a sidebar Only if the screen max-width is >900px?

I have been playing around with media queries quite a bit lately and I love the concept. It is so easy to display images or change div floats depending upon what the users screen max-width is. I'm ...
shawn's user avatar
  • 752
1 vote
2 answers
237 views

Static Front Page problem

My theme uses the front-page.php file to display a number of items on the front page including a slideshow and some featured items. I have also designed it so the static front page as set in the ...
byronyasgur's user avatar
  • 3,022
1 vote
1 answer
156 views

Template plugin for blog posts? [closed]

can someone recommend a plugin to do the following? My wordpress CMS has two types of users: administrator and editor, both of whom are not technologically savvy, so they need things to be super ...
learningtech's user avatar