• Summary of issue: I am building a website using WordPress as CMS and inside the website I want to have a blog with a different layout than the rest of the site.

    In this blog I want to have all the posts, which in other parts of the site are displayed by category.
    To achieve that I have made a page called “blog” and set the posts page to that page. All fine so far.

    To make the blog look different I can re-write “index.php” (the rest of the site uses archive and page templates) and change the layout, display a different sidebar etc. However if you open a post from the blog, the post is displayed with the site’s layout. If I change “single.php” to match the blog, then if you open the post from the site it is displayed with the blog’s layout.

    I’ve tried different things, like category templates and more but I can’t think of a solution for my problem.

    There might be an easier way to do it that I can’t think of.
    Any solution or ideas please?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi

    Look into custom page templates and query_posts – they are probably what you are looking for.

    https://codex.www.ads-software.com/Pages#Creating_Your_Own_Page_Templates

    https://codex.www.ads-software.com/Template_Tags/query_posts

    Here is some code that lets you have more than one single.php template.

    Unique Single template
    Suppose you want to use different Single template to display individual post in certain category. You can use the in_category to check what category is the post stored in and then use different Single template. In your default single.php, enter the code below. If the post is in category 1, use single1.php, elseif in category 2, use single2.php, otherwise use single_other.php.

    <?php $post = $wp_query->post;
      if ( in_category('1') ) {
      include(TEMPLATEPATH . '/single1.php');
      } elseif ( in_category('2') ) {
      include(TEMPLATEPATH . '/single2.php');
      } else {
      include(TEMPLATEPATH . '/single_other.php');
      } ?>

    1) You must use category ID codes that exist on your site
    2) In the code example, single_other.php becomes the default sidebar.
    3) To set this up, rename your theme’s file single.php to the name of the new default file – in the example that is single_other.php (use whatever name you prefer).
    4) Make a new file in your theme folder called single.php – paste the code I posted in that new file. that is the only thing that should be in the new single.php.
    5) Make new files single1.php, single2.php, single3.php, setting them up however you wish as custom single templates.
    Give them whatever file name you want. Just change the name of the file for that category in the IF statement I posted to match the actual filename you give the file.

    Thread Starter mpiftex

    (@mpiftex)

    Thanks for the reply stvwlf.
    However I don’t think that this is the solution to my problem.

    You see I want to change the way of the post appears depending on where the post was opened:
    if it was opened from the website (display by category), I want it to appear with the site’s layout
    if it was opened from the blog(display as posts page), I want it to appear with the blog’s layout
    In both cases the post is in a category but I want it to appear differently in different parts of the site.

    I don’t know if that is even possible, that is why I’m trying to think of another way but i’m out of ideas.

    Hi – That is exactly what those pages I sent you will allow you to do.

    You would create a template file for your blog, looking however you want. Then within WP, create a static page named Blog. Assign a custom page template to the page “blog”.

    Then go to Admin / Settings / Reading and set the page Blog as the Posts Page.

    Through this the posts are displayed on a page that uses a custom template that looks like “blog”. All the other pages will display using the “sites layout”

    Thread Starter mpiftex

    (@mpiftex)

    I appreciate the help stvwlf!

    I create a page template named blog and i assign it to the static page blog. I open the blog page and it’s displayed with the blog template layout. Great.

    However as soon as I set the page blog as the Posts Page, the page blog is not displayed according to the blog template but according to index.php template. I assume that the Posts Page is not a static page anymore.

    As I wrote on the first post, I can edit index.php and make it appear just like blog template does but still, when I click on a post’s title (to open that post separately), it is displayed accordingly to the single.php template (which is different than blog template and index.php).

    I hope I’m making myself clear.. I’m sorry for the not-so-clear and possibly confusing use of the terms.

    Hi

    OK, now I see what you mean.

    The problem becomes though, even if you can make this work, where does it stop. Meaning, if I am looking at a single post formatted as the blog styling, what happens if I click the previous post link at the bottom of the single post page. Is it supposed to display as the blog or as the site? And if I find the same post on a different page then they are supposed to display differently if I encounter the post on a category page instead of the blog page.

    In researching this I came across an interesting idea – see WhoAmI’s comment in this post about using an alternate stylesheet.

    I was just wondering, given the point I made above, if on your blog page it made sense to display the single posts in a thickbox overlay, so when they exit the single post display they go right back to the blog-styled blog page. Perhaps a global variable can be set on, which single.php then checks for the presence of – if that variable exists then it uses the blog styling otherwise the default styling.

    I’m not coming up with anything more solid than that at the moment.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Blog inside the website’ is closed to new replies.