• For reference: http://wordpress.org/support/index.php?action=vthread&forum=3&topic=6701
    I’m trying to create single post pages in order to fake a static look. For example, I’ll have info, about, company, faq and contact that should all be static pages.
    However, if I make a new category called ‘Static’, it is placed below the ‘General’ category on my main menu. In addition, the posts show up as a daily in the main blog.
    When I set the posts to Private and link to them directly in the HTML, I get a ‘sorry no posts match your criteria’ message. I need a way to hide the category, the post and link directly to that post from my ‘static’ links.
    Just can’t seem to work it out.

Viewing 9 replies - 1 through 9 (of 9 total)
  • i’m looking something for the same problem! 🙂
    thank you mat for writining my question! 🙂

    I managed to put together a method that changes nothing but index.php (so it’s upgrade-proof). It has the following properties:

    • Doesn’t show static category in category listing
    • Doesn’t show static posts on front page
    • Shows static posts using their own post layout when displayed
    • Allows searching of both static and non-static posts, putting all posts in the correct layout
    • When you click on a calendar date or search for posts by month or day, you see the static post in a slightly altered template that shows the last update (assuming you update your timestamps)
    • Doesn’t change index.php, so it’s upgrade-proof!

    It also has the following limitations:

    • Still sydicates entries through RSS (if timestamp is updated)
    • May require alteration of plugins/hacks that lists posts on front page, because it doesn’t unset the static posts, just chooses whether or not to display them

    Basically, it just requires the addition of an if-else statement in the posts loop, and one quick change to the menu.
    First, the menu. Change the categories list to exclude your static category like so:
    <?php wp_list_cats('exclude=3'); ?>
    Adding the exclude statement (and of course replacing with the ID of your static category) takes care of that part. Now, to change the loop. Immediately after these two lines:
    <div id="content">
    <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?>

    add the following beginning to the if statement:
    <?php if (!in_category(3)) { //begin regular loop ?>
    Now, once the regular loop has finished, we close the if statement and start the elseif statement that will show the static page under specific conditions. Find the following code:
    <?php include(ABSPATH . 'wp-comments.php'); ?>
    </div>

    Immediately after it insert:
    <?php
    } //end regular loop
    elseif ($single==true || !empty($search) || !empty($cat) || intval($monthnum)) { //begin static pages loop ?>

    The parameters of the elseif statement can of course be modified to meet your needs. Now, we just create a static content layout of our own choosing. Here’s what I recommend:
    <?php
    if ($single) { ?>
    <h2 class='static'>/static/<?php echo $post->post_name; ?>/">
    <?php the_title(); ?>
    </h2>
    <? }
    else the_date('','<h2>','</h2>');
    ?>
    <?php if (!$single) { ?>
    <h3 class="storytitle" id="post-<?php the_ID(); ?>">/static/<?php echo $post->post_name; ?>/"><?php the_title(); ?> - Updated</h3>
    <?php } ?>
    <div class="storycontent"><?php the_content(); ?></div>
    <div class="meta" id="static">Last updated <?php the_date('','',''); ?> by <?php the_author(); ?>.</div>
    <?php } //end static pages loop ?>

    Let me know how this works for you.

    Update: I lied about a couple things. If you use the static post loop I use, you also need to update .htaccess with the following lines:
    RewriteEngine on
    RewriteRule ^static/(.+) /index.php?category_name=static&name=$1 [QSA]

    That will make my “modified” permalink work for you. Instead of putting in the permalink manually in the loop code, you could modify the function the_permalink() to output the appropriate link if the page was static. This wouldn’t be upgrade-proof though.
    As for the syndication problem, I can think of two ways to go about this problem. One is upgrade-proof and one is not. The first would be to unset the posts in if they are being syndicted (I have not tried this, but this would involve adding an if statement to wp-blog-header.php). The alternative approach (which I also have not tried) involves putting the date of last update in a meta tag, and not changing the timestamp of the PHP file. Then, change the “last updated” part of the static post loop to get the date from the post meta. Instead of being syndicated whenever there is an update, this would now only syndicate when a new static page is created. The downside of this, of course, is that when posts are displayed by month or day, the static post is shown as being from the time it was first created, not the time it was last updated. However, either of these approaches could work depending on your needs.

    I noted one other error in my previous code when I went to validate my pages. Right now, the static pages loop I listed puts the “last updated” information in a div with class of meta and id of static. I initially did that so that I could right-align the div. However, if you look at a month in which you updated more than one static page, then this will not validate. That should be changed, either by making a separate class in your CSS for this information or by including style information directly in the tag.

    Yes, that should be a new line, not replacing either of those two lines.

    Thread Starter matius

    (@matius)

    When I try to change first line to: <?php wp_list_cats(‘exclude=3’); ?>
    I get an error that screws up the whole site.
    Am I suppose to be changing the ‘wp_list_cats’ in ‘wp-includes/template-functions-category.php’ >> just doesn’t work…

    The code
    <?php wp_list_cats('exclude=3'); ?>
    works OK for me – all I changed was that line and added the extra if statement to exclude the display of posts from a certain catgeory.
    Thanks for the info thefreefood, now my calendar items just show up in the calendar and no where else.

    My hope is that with 1.3 this approach can be greatly simplified, or even put into a single plugin. I put on the API Wishlist a hook that would allow plugins to unset posts in the blog header before anything was displayed. If that happens, then this hack should become much easier to set up.

    so wait. do we get the best of all worlds with this hack? i basically want my whole site to look static minus the blog and main page. would i still be able to categorize everything and then come up in the static look?
    i basically want to keep the layout and look of my website but have all the nice little things that WP offers (multi authors, blog, catigorizing, dynamicness etc etc)
    🙂

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Single Post Pages…Static Look’ is closed to new replies.