Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8124779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:34:39+00:00 2026-06-06T06:34:39+00:00

I think my previous question was over complicated and, to be honest, was confusing

  • 0

I think my previous question was over complicated and, to be honest, was confusing me, nevermind the people trying to answer.

I currently have to pages, both with one category of posts assigned to them, however both post pages are using the same content.php and content-single.php, but i was both pages to use different iterations of these pages for cosmetic reasons.

As an example, visit http://dev.n8geeks.com/blog/ and click on the first blog post. It displays a thumbnail, which is cool and is what i want. However, now on the “videos” page as seen here; http://dev.n8geeks.com/videos/ (once there, click on the post) it also shows the thumbnail box (but no thumbnails will be attached on this posts page category).

This is why i need to user different iterations of content.php and content-single.php, but i simply don’t know how. It would also be great if the “videos” page had the same formatting as the “blog” page, but again, i don’t know how to achieve this.

The code i’m using for the current “videos” page is as below.

<?php get_header(); ?>

<div id="content">
<div id="main">

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; else: endif; ?>

<?php query_posts('category_name='.get_the_title().'&post_status=publish,future');?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h1 class="entry-title"><a href="<?php the_permalink(); ?>">
<?php the_title();  ?></a></h1>
<p><?php the_content(); ?>
<?php endwhile; else: endif; ?>

</div>
</div>

<?php get_footer(); ?>

Thanks in advance, i really appreciate any help like you wouldn’t believe – it’s 4:33am and i’m going insane trying to find a fix for this.

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:34:40+00:00Added an answer on June 6, 2026 at 6:34 am

    Still extremely confusing, haha, but from the sounds of it you want different templates to show up based on which category the post is in when you’re viewing a single post?

    If so, you could try setting this as you single.php:

    <?php get_header(); ?>
    
        <?php
            if ( have_posts() ) { the_post(); rewind_posts(); }
            if ( in_category(1) || in_category(2) ) {
                include(TEMPLATEPATH . '/single-cat1-2.php');
            }
            else {
                include(TEMPLATEPATH . '/single-default.php');
            }
        ?>
    
    <?php get_footer(); ?>
    

    (from http://wordpress.org/support/topic/alternate-single-post-template-for-specific-categories)

    And create the files ‘single-cat1-2.php’ and ‘single-default.php’, just add to the if statement checking to see if the post is in a certain category (or categories) and load the correct template. You can use ID, name, and their slug as selectors for the in_category function as well, read more here.

    EDIT:
    Kay, well you do need to learn plugin programming to really do this. I’ve begun a quick plugin for you to help you out. It works, just isn’t perfect. You could definitely use a different system, like tying the categories in the category menu, but I didn’t feel like playing with the Settings API for that page.

    So make a new directory in your plugins directory, call it PostCatTheme, make a new file in there called index.php and put this in it:

    <?php
    /*
     * Plugin Name: Post Category Templates
     */
    //Replace __FILE__ with whatever the real path is because of symbolic link
    
    /**
     * Allows declarations of which categories a single-post template is assigned to
     */
    class WordPressPostCatTheme
    {
        private $pluginDir, $templates;
    
        function __construct ()
        {
            $this->pluginDir = dirname(__FILE__);
    
            add_action("init", array($this, "load"));
            add_filter('single_template', array($this, 'get_post_template'));
        }
    
        public function WPCT_deactivate ()
        {
            delete_option("PostCatTheme_templates");
        }
    
        public function load ()
        {
            register_deactivation_hook( __FILE__, array(&$this, 'WPCT_deactivate') );
    
            $this->templates = get_option("PostCatTheme_templates");
            if ($this->templates === FALSE)
            {
                $this->templates = $this->get_post_templates();
                update_option("PostCatTheme_templates", $this->templates);
            }
        }
    
        //  This function scans the template files of the active theme, 
        //  and returns an array of [category] => {file}.php]
        public function get_post_templates()
        {
            $themes = get_themes();
            $theme = get_current_theme();
            $templates = $themes[$theme]['Template Files'];
            $post_templates = array();
    
            $base = array(trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()));
    
            foreach ((array)$templates as $template)
            {
                $template = WP_CONTENT_DIR . str_replace(WP_CONTENT_DIR, '', $template); 
                $basename = str_replace($base, '', $template);
    
                // don't allow template files in subdirectories
                if (false !== strpos($basename, '/'))
                    continue;
    
                $template_data = implode('', file( $template ));
    
                $categories = '';
                if (preg_match( '|Categories (.*)$|mi', $template_data, $categories))
                    $categories = _cleanup_header_comment($categories[1]);
    
                //The categories are split by a | (pipe), if there aren't any pipes, assume it's just
                //one category, otherwise split at the pipe
                if (empty($categories))
                    continue;
    
                if (strpos($categories, "|") === FALSE)
                    $categories = array($categories);
                else
                    $categories = explode("|", $categories);
    
                foreach ($categories as $category)
                {
                    if (!empty($category))
                    {
                        if (isset($post_templates[$category]))
                            throw new Exception("Error, category assigned to more than one template");
    
                        if(basename($template) != basename(__FILE__))
                            $post_templates[trim($category)] = $basename;
                    }
                }
            }
            //file_put_contents($this->pluginDir . "/log", json_encode($post_templates));
            return $post_templates;
        }
    
    
        //  Filter the single template value, and replace it with
        //  the template chosen by the user, if they chose one.
        function get_post_template($template)
        {
            global $post;
    
            $cats = wp_get_post_categories($post->ID);
    
            //Go through each category, until one hits
            foreach ($cats as $c)
            {
                $templateP = $this->templates[$c];
    
                if(!empty($templateP) && file_exists(TEMPLATEPATH . "/{$templateP}"))
                { 
                    $template = TEMPLATEPATH . "/{$templateP}";
                    break;
                }
            }
            return $template;
        }
    }
    
    if (!isset($PostCatThemePlugin))
        $PostCatThemePlugin = new WordPressPostCatTheme;
    ?>
    

    After that, in your custom single.php template, add the code Categories: 1|2 in the header section (where Template Name is). Whenever you change or add these, make sure to deactivate and reactivate the plugin, to refresh the cache that this information is stored in.

    To get the ID of a category, edit a category and in the URL, the number after tag_ID= is the category’s ID.

    Hope that helps some,
    Max

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to give my previous question a second chance since I think I
I have a previous question which I have provided my solution; however, I don't
In generalisation of my previous question , how can a weighted average over cell
This is kind of a followup on my previous question . I have an
I have a question related to this previous question of mine . In an
Ok I think I'm getting the previous year instead of the previous day, but
Think I have an integer array like this: a[0]=60; a[1]=321; a[2]=5; now I want
Think my problem is I am trying to sum a count in the same
I think I have a basic understanding of this, but am hoping that someone
I sort of answered my own question I think but I want to make

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.