• Hello,
    I’m quite a beginner in WP and my question is related to templates. What I want to achieve:
    1. For the main blog page, i will use the default 2-columns template.
    2. Now, when I will display single article page, I’d like to have completely different design: there will be only one column – with the article text and comments, and above the article, there will be the “path” to that article, like “myblogsite.com -> Category XYZ -> Article ABC”. So, the blog title and the right panel will not be displayed.
    How can I achieve this in some standard way? When I look at the URL’s, I see that there is only one template, index.php, which is called with different parameters for all pages. Now, when I want different layouts for index page and article page, or maybe even different for category page, should I create another php file for article, like “article.php”, which will be called from main index.php, or should I stick just with index.php and achieve my goal with php code? Or is there yet another solution?
    Thank you,
    Soso

Viewing 14 replies - 1 through 14 (of 14 total)
  • Well, with minor mods of the starting template, you could use PHP to check:
    if ($p!=””) then
    {
    …enclose all the stuff you want to drop when on article page
    }
    With major mods to index, and CSS work, you could achieve a lot more. I have one check in index.php which is for the ‘front page’ detection, and I add in a div wrapper when I’m on an article page. With all that, I echo out all data I might want displayed, and then use CSS to cull stuff I don’t want or shift elements around. I still need to go back to the RSS feeds, the print.css, and tweak all of that, but I can now do some pretty creative changes. Look at http://www.chait.net, and note the subtle (but all-in-CSS) changes between the article display on the front page or any category list, and an article/post page. I could pretty easily modify it toward what you’re suggesting, by making the left and right columns display:none, and the main block width:100%. It’d be maybe 10 lines max of added CSS stylings. 😉 Okay, maybe a minor tweak or two to the php as well.
    Once index.php is ‘well factored’ for being heavily CSS-templated (it is decently factored for basic CSS work), you can do most anything imagineable.
    Anyone who hasn’t been to http://www.csszengarden.com, it’ll blow your mind.
    =d

    David,
    Looks like we are going to have to ask you to write some tutorials for us! 🙂
    Craig.

    There’s mention in the readme about the ability to use single-post templates, but TBH I haven’t a clue how you do that.

    Thread Starter Soso

    (@soso)

    Thank you davidchait, I’ll try the php code+css approach. Regarding the display:none hack, I’m not sure if that is only “maybe 10 lines max of added CSS stylings.” The non-displayed code will still remain in the html source, so it will be downloaded during browsing -> a waste of bandwidth. So I don’t quite like that solution.
    BTW: Your CSS list of categories is not displayed correctly in Opera browser (latest version). Good design, anyway!
    Soso

    Yeah, I need to install ALL the various browsers and do more testing. Opera has had issues, and apparently has fixed a bunch of them in the latest point release from what I’ve heard. There are some great sites on CSS and browser compatability, and MY GOD, it’s like coding for different platforms! 😉
    Understand also that ‘waste of bandwidth’ is truly relative. It depends on how much content you have on your sidebars, might you EVER want any of that content available on a single-post page (i.e., don’t make a pain for yourself in the future), how dynamic is your sidebar content (i.e., the hit of going out to download a RSS aggregation feed is an order of magnitude larger than sending, and ‘hiding’ the results…).
    If you have reasonably static sidebars, hiding is simple.
    If you don’t ever, ever want that data available, just do the hide in PHP.
    If the current index file is something like this:
    .. includes
    .. header
    .. menu
    .. content
    Then, what you want is (this is obvious pseudo-code…):
    .. includes
    $justArticle = ($p==””);
    .. header
    if (!$justArticle)
    {
    .. menu
    }
    if ($justArticle) echo “<div id=”justArticle”>”
    .. content
    if ($justArticle) echo “</div>”
    — AND, then add some css to ‘specialize’ the just-article content. If you look at the source of http://www.chait.net, you’ll see that I actually wrapper >inside< the $posts loop — which is really where you want to do the $justArticle stuff. Then it becomes a specialization on the content. In other words, you might have:
    #main { .. css rules .. }
    and add
    #main .justArticle { .. overrides ‘base’ layout, like width:100% or something… }
    … I’d have to go back to the ‘raw’ index.php to give you specific examples. Over time, I’d hope to work with the WP folks here and actually get some of my ‘canonical layout’ stylings pushed into index.php so everyone in WP-land can benefit, and we can really kick it up a notch.
    =d

    Thread Starter Soso

    (@soso)

    Hi david,
    I tried the “$justArticle” approach and it works, but the problem is that the <?php directive cannot be nested, so I rather end up with a lot of <?php if ($justArticle …, blocks of code, or I need to “echo” the html code. So I’m now trying to have two different templates, like index.php and article.php. It seems to work for me.
    Yes, you are right, CSS is a pain, and I’m already tempted to create the homepage layout by using table! I already tried the CSS Layout Generator, which seems to produce correct CSS code for layout, but there are so many nested <div>’s to make it workable, so the resulting code is more complicated than using table…
    Anyway, thanks for your help. I’ll post the result of my work, when it will be done. (If that’s not agains the forum policy, of course).
    Soso.

    ok, that’s exactly what I wanna do but after reading this thread over and over, I still don’t have a clue how to get some parts to be visible/hidden only on individual entries.
    I know CSS (a little) but not PHP and I’m affraid I’m too retarded to understand the pseudo-code above. Anyone could explain w/ real code or direct me to a file I could look at?
    I just don’t get what/where PHP code I have to add to te index.php file. I’d rather not use a CSS display: none; type solution ’cause I pretty much want to completely remove the sidebar #menu div tag from the individual post.
    Looked on the WIKI but couldn’t find anything…
    Thanks! 🙂

    so…
    For now, here’s what I did. I put this in the header:

    <style type="text/css" media="screen">
    @import url( <?php echo $siteurl; ?><?php if ($p!="") { echo '/wp-layout_indy.css'; } else { echo '/wp-layout.css'; } ?> );
    </style>

    And I tweak both CSS files to make the individual entries and the main look different.
    Somehow I feel it’s not the best way to go about it… Is there a better way?

    It used to be easy to do this by using different php files as your base pages, then adding parameters to some of the template tags so that links to individual entries redirect to that page rather than sty on the index.php. In fact this is how my whole blog is designed. The individual pages with their different templates work fine, however the parameters to create links to those pages no longer work (as described in this thread: http://wordpress.org/support/3/1622).
    I have got around the problem for now by putting my single entry page into the options as the blog file name but this means all my archive links are messed up (ie go to the single entry page, which isn’t set up for multiple entries, rather than the index page, which is) and the ‘vew site’ link within the editing interface also goes to the wrong place. The alternative for now is manually changing the fuctions within the program files so that links to individual entries go to the different page (which I will probably so next weekend) but hopefully at some stage this functionality will be put back into wordpress.
    All the stuff in this thread about changing the index.php page to show different things is a perfectly viable solution. It’s just that using seperate files was a lot easier to set up.

    I’ve been messing with WordPress for a few days now. It’s a great program. Easy to use etc.. but I’m blown away that it doesn’t support multiple templates. What up with that? Does anyone know if it will ever support differen templates for different categories?
    To me this is a major flaw. And hacking CSS, and PHP to get it to happen is too messy. Any plugins to do this??

    Alright, I sorted it out.
    On a hunch, I changed <b>category.php</b> to <b>somethingelse.php</b>, altered the .htaccess mod_rewrite, and it worked perfectly.
    Thanks for the tips!

    I spoke too soon. I got the two additional templates to work, but then other links didn’t work — either the category links or the monthly archive links (I’ve forgotten which).
    What I’m trying to do is to have pretty URLs, templates for both category pages and single post pages. I wish I could also convert the prettified URLs to page.php … which can be done, but also breaks other links (category or archive).
    As I’ve seen similar posts, I think I’ll compile everything and start a new thread. Maybe if we have them all together, a pattern will emerge, and a solution.

    For me, only having a single template for my blog is one of the great virtues of WordPress. I can see why some people might want separate templates for main page, single entries, categories etc. What I can’t understand is why they would be using WordPress when there are other tools that do this stuff without the need for klugy hacks.

    it’s kludgy only if you don’t know what you’re doing.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Can I have different templates for main page and s’ is closed to new replies.