Forum

Thread tagged as: Question, Configuration, Blog

Blog Templates

Hi All,

I have read several posts on the topic but i'm not completely clear however how i would implement.

Can anybody confirm if i can have separate post.php pages for each blog section? or to word it another way, one post .php page that would have a different layout depending on the blog section.

thanks in advance

Steve Forbes

Steve Forbes 0 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You're thinking about it from the wrong direction. post.php is just an example page we bundle with the app so you can see how you might put things together.

Work out what pages you want, and then put the blog page functions on them to bring in the content you want on those pages.

Thanks for the quick response. Sure thats makes sense.

So if i had the exact same structure as your demo blog, but now have two sections to my blog A and B.

If you happen to land on a page that is displaying section A rather than B's latest posts when you click its link populated by postURL does it not simply call on the post.php?

Am i still getting mixed up?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I don't understand this bit:

when you click its link populated by postURL does it not simply call on the post.php?

could you rephrase it?

Ok, so if i take the files you provide with the blog app. and use your structure entirely. But now i add another section. So i have two sections.

If i open up the index.php page in the blog directory i view my posts populated by my post_in_list template. Once i click on a blog title this takes me to the post and displays it using the post.php page within the blog directory. Using href="<perch:blog id="postURL" />"

Im guessing that due to my settings for blog post page path being /blog/{postSlug} this is how it builds the URL.

So i'm just confused as how i can place the section into the URL to call it?

Apologise if i'm barking up the wrong tree (when can we sign up to perch curses?).

cheers in advance.

Could i do something like on the archive page, use perch_get?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to include the section slug in your blog post path. You can then use perch_get() to read it back from the URL and filter the list on the section.

Hi Drew,

I'm going to use Perch Categories for this now, it's probably the better solution.

Thanks for your help.

Hi Drew

I'm going to re visit this. I'm aware of the below but I don't see how this allows me to then display the post within a different post.php

To clarify I want to use different post.php pages for each section of my blog as I use the blog for displaying posts but also case studies so require a different page layout.

Any help would be great.

Drew McLellan said:

You need to include the section slug in your blog post path. You can then use perch_get() to read it back from the URL and filter the list on the section.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Put the section slug in the URL. You can then switch what you're doing on the page based on the slug.

Is there a reference to this in the docs? if not could you humour me a post a little example if i promise not to post to the forum for two two weeks? ;-)

Drew McLellan

Drew McLellan 2638 points
Perch Support

if (perch_get('section')=='my-nice-section') {
    ... do this ...
} else {
    ... do that ...
}

Ok, i'm struggling on this now. I have the below in my post.php

            <?php if (perch_get('section')=='case-study') {

            echo '<div class="column column--full">
                     <div class="item--container">';


                perch_blog_custom(array(
                    'template' => 'posts/Case_Study.html',
                    'count'=> 1
                ));

                echo '</div>
                              </div><!--/full-->';



            } else {





                echo '<div class="column column--two-thirds">
                      <div class="item--container">';


                perch_blog_post(perch_get('s'));


                echo '</div>
                              </div><!--/two-thirds-->';

                echo '<div class="column colun--one-third">
                     <div class="conatiner">
                     <nav class="sidebar">';

                perch_blog_categories('category_link--custom.html');
                perch_blog_tags('tag_link--custom.html');
                perch_blog_date_archive_years('year_link--custom.html');
                perch_blog_date_archive_months('months_year_link--custom.html');

                echo "</nav><!-- /sidebar -->
                          </div><!-- /container -->
                      </div><!-- /one-third -->";


            }
            ?>  

And i have the this in my template

  <a href="<perch:blog id="postURL" />?section=<perch:blog id="sectionSlug" />" rel="bookmark" class="entry-title"><perch:blog id="postTitle" /></a>

But although i can see the section slug in the URL my if statement fails and it passes straight onto the else.

Im doing something stupid probably, but i've been on this for 1.5 days now so any help/advice i assure you is appreciated.

Dan

Ok I've been playing some more and if i strip out the html and keep that in my template it seems to work ok, but i need the sidebar and the php thats in that for the archive links. This cant then run in the template as gets commented out.

Hi Drew,

Testing shows my If statement being ignored, i have

            <?php 

            if (perch_get('section') == 'case-study') {
                perch_blog_post(perch_get('s'));

            } else {
                perch_blog_post(perch_get('s'));


                echo '<div class="column column--one-third">
                      <div class="container">
                      <nav class="sidebar">';

                    perch_blog_categories('category_link--custom.html');

                    perch_blog_tags('tag_link--custom.html');

                    perch_blog_date_archive_years('year_link--custom.html');

                    perch_blog_date_archive_months('months_year_link--custom.html');

                echo '</nav><!-- /sidebar -->
                      </div><!-- /container -->
                      </div><!-- /one-third -->';



            }
            ?>  

I can see the section "case-stufy" in the url string but the statement ignores it.

any thoughts be much appreciated?

Dan

Drew McLellan

Drew McLellan 2638 points
Perch Support

What is the value of perch_get('section') if you output it to the page?

forgive me but is this as simple as. If so nothing

<h1><?php perch_get('section'); ?></h1>
Drew McLellan

Drew McLellan 2638 points
Perch Support

<?php echo perch_get('section'); ?>

What does your URL look like at that point?

/blog/1970-01-01-sharing-your-story?section=case-study

but nothing gets outputted at the location of below.

<?php echo perch_get('section'); ?>
Drew McLellan

Drew McLellan 2638 points
Perch Support

It looks like you're rewriting the URLs, so you'll need to add the section slug as part of the URL path rather than as a query string.