If I have this URL for my custom taxonomy term /
how can I show it as the main page /
like it is available to do for the static pages at Setings
> Reading
menu?
.htaccess
solutions are acceptable, changing theme's index.php
is not.
Update:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_URI} ^/work_type/vehicle-transporting/
RewriteRule ^(.*)$ / [P]
</IfModule>
# END WordPress
Why it didn't help?
If I have this URL for my custom taxonomy term http://example/work_type/vehicle-transporting/
how can I show it as the main page http://example/
like it is available to do for the static pages at Setings
> Reading
menu?
.htaccess
solutions are acceptable, changing theme's index.php
is not.
Update:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_URI} ^/work_type/vehicle-transporting/
RewriteRule ^(.*)$ / [P]
</IfModule>
# END WordPress
Why it didn't help?
Share Improve this question edited Jun 28, 2013 at 15:51 Pavel K asked Jun 28, 2013 at 15:13 Pavel KPavel K 1012 silver badges7 bronze badges 4 |3 Answers
Reset to default 2I agree with @KrzysiekDróżdż While you should probably be able to do this it might be unnecessary work.
However, this works with I test it, just change the category/term name and the template name (the part in get_template_part
), and maybe the is_main_query() && $qry->is_home()
conditional if you need to:
function pregp_home_cat_wpse_104619($qry) {
if (is_main_query() && $qry->is_home()) {
$qry->set('category_name','aciform');
$qry->set('ignore_sticky_posts',true);
add_action('template_redirect','tr_home_cat_wpse_104619');
}
}
add_action('pre_get_posts','pregp_home_cat_wpse_104619');
function tr_home_cat_wpse_104619() {
get_template_part('category','aciform');
exit;
}
I have never tried to do this in production, so "when I test it" means that I've spent about 10 minutes and don't see any obvious problems. I make no promises.
Barely tested. Possibly buggy. Caveat emptor. No refunds.
Solution 1.
One solution would be to use home.php
template file, or use static page as front page and then use front-page.php
template file.
You can use get_template_part
function to include your taxonomy template inside, or use template_include
hook to redirect one of front-page
/home
template to your custom taxonomy template.
Solution 2.
You can also use pre_get_posts
filter to change main WP query in such way, that it shows only posts from this custom taxonomy.
- Copy your single taxonomy template code.
- Paste that into your home page template. Or create a new one.
- Add the following to the top of the page $post->ID = XX (XX being the ID of your post)
- Set that template as your homepage in the WP settings.
RewriteCond %{REQUEST_URI} ^/work_type/vehicle-transporting/
RewriteRule ^(.*)$ / [P]
I tried this but got no success – Pavel K Commented Jun 28, 2013 at 15:40front-page.php
template to show posts from this taxonomy? Or just usehome.php
template? – Krzysiek Dróżdż Commented Jun 28, 2013 at 15:46