WordPress.org

Ready to get started?Download WordPress

Ideas

Introduce single.php with category ID i.e. single-5.php

  1. dan_ctow
    Member

    12345

    Category-#id.php works wonderfully when you have multiple cats with multiple layouts.

    I think that having the same facility for single.php will help keep things simpler and more organised.

    Posted: 6 months ago #
  2. Gezim Basha
    Member

    12345

    Hopefully they will implement this in the standard installation, however, given that you might want this right now you can do it this way:

    Go to your installation and find the file "template.php"; It resides on:

    wp-includes/template.php

    Find the function get_simple_template() which should be around line 288. Now add this around line 290.

    $id = get_queried_object_id();

    And then on line 296, add another if-conditional, and write this:

    if ( $id )
       $templates[] = "single-$id.php";

    Save the file and now you should be able to query your theme's single-id.php files. Please take a look at this gist to get the full code.

    Posted: 6 months ago #
  3. Ipstenu (Mika Epstein)
    Administrator

    NO! NEVER EDIT CORE FILES! NEVER SUGGEST IT!

    This is terrible advice for 99.99999% of users. Please don't do it.

    Are you trying to make a template for one specific page as a one-off? Most people don't know what the one page ID is (and slugs change a lot) so I would recommend a plugin like http://wordpress.org/plugins/custom-post-template/

    Posted: 6 months ago #
  4. Gezim Basha
    Member

    12345

    Actually, I am pretty sure I've misunderstood the whole question. The OP wants to create a single-$id.php file where the id corresponds to the category id.

    This too can be done by editing core files, however, as its clearly a bad idea I will refrain from guiding him further XD.

    Posted: 6 months ago #
  5. Ipstenu (Mika Epstein)
    Administrator

    Gezim, if your 'fix' for things has been to edit core, you're going to be miserable when we introduce auto-updates in 3.7 Don't edit core. Unless you're doing it to edit code to provide an upstream patch to WordPress, it's a horrible idea.

    The OP wants to create a single-$id.php file where the id corresponds to the category id.

    http://wphierarchy.com/ has a lot of cool info, but for making all posts in a specific category look one way, you would have to edit your theme and tweak it 'If cat A, do foo' and so on.

    Posted: 6 months ago #
  6. Ipstenu (Mika Epstein)
    Administrator

    Douple posting... I'm approving Gezim's plugin right now ;) Yay! A fix!

    Posted: 6 months ago #
  7. Gezim Basha
    Member

    12345

    Yeah, I've just made a simple plugin to mitigate this problem. Anyone interested just search for Single ID on the plugin repositories and it should be there.

    Ipstenu, thanks for the heads up. Though I rarely edit the core (only when I'm lazy) I will start changing that habit now that auto-update is coming. Although when I think of it, I could just edit the core and stop them XD.

    Posted: 6 months ago #
  8. Ipstenu (Mika Epstein)
    Administrator

    There are many reasons we tell you to never edit core files directly. It's a terrible habit. If you edit the core files, you have to edit them every time you want to update. And that means you put yourself at risk security vulnerabilities and inconsistencies with the way it acts. Plugins and themes stop working, and if you come asking for help, you won't get any save "Don't edit core!!!!"

    That's why we have the hooks and Apis :)

    Posted: 6 months ago #

RSS feed for this topic

Reply

You must log in to post.

  • Rating

    12345
    4 Votes
  • Status

    This idea is under consideration