0
votes

I am using a wordpress template. I have many categories, like, Adventure, Sports, News. Now, each category have posts in it, I know singlep.php is generating the all kind of posts. Suppose, if you click on News, it will show all the posts related to News. Every posts is identified as same page type "Post". But, I want to call a separate Post php file instead of single.php, when Adventure is clicked. Means, when I am browsing the posts of Adventure category, then it should come from example.php . Example.php is the file that I want to link with Adventure. I need help regarding that. It will be like,

if (Category == Adventure)
call the example.php
else
single.php

Where should I focus to do this. Is there anything related to functions.php ? Also, how wordpress calls the Single.php ? So that I can instruct it to call my example.php too.

1

1 Answers

0
votes

Have you try to edit your single.php ?

in_category ( int|string|array $category, int|object $post = null )

Sample from wordpress site itself

if ( in_category('fruit') ) {
    include 'single-fruit.php';
} elseif ( in_category('vegetables') ) {
    include 'single-vegetables.php';
} else {
    // Continue with normal Loop
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    // ...
}

in_category. This also could be a reference, Template Hierarcy: single post.


This can be an option to customize header for each category for single post by adding custom header file and edit single.php file

At the very top of single.php file

if(in_category('apple')){
    get_header('fruits');
}elseif(in_category('cabbage')){
    get_header('vegetables');
}else{
    get_header();
}

Then creates your own custom header with the exact name as example code above as header-fruits.php & header-vegetables.php