Jump to content

Blog Profile: Render individual posts differently.


Pascal
 Share

Recommended Posts

Hi!

I am working on customizing the Blog Profile. I wonder if it is possible to have different markup for individual posts and the paginated post list. I edited the markup/post.php for the view of an individual post. However, in the post list, several elements should not be shown. For example, I need the headline of the posts in the blog's landing page to have different classes than when viewing an individual post. 

First I thought this was because markup/posts.php includes markup/post.php. So I created markup/post_list.php and included it in markup/post.php. However then a single blog post was also rendered with the markup from markup/post_list.php. I don't know if there is any easy solution, I can't wrap my head around how some of these files are connected. Can anyone help me on this one?

Edit: Got it! Just count the elements of the $posts array and generate different markup if it is > 1.

        <?php
        $pagecount = count($posts);
        if($pagecount == 1) {
            $parentpage = $page->parent->url;
            echo "<div class='arrow'><a href='$parentpage'>←</a></div>";
        }
        ?>
 

However, feel free to suggest anything easier or more elegant. 

Link to comment
Share on other sites

Hi Pascal,

The function renderPosts which renders one or multiple posts, takes an argument $small. When small is set to true, the blog profile hides for example the comments and other things.

So I suggest that you edit /site/templates/markup/post.php and give your classes based on the $small.

$small is true when rendering multiple post and false when rendering one post (detail-view).

// 'post-list' class when $small is true, otherwise 'post-detail'
$class = ($small) ? 'post-list' : 'post';
echo "<div class='post {$class}'>";
  • Like 1
Link to comment
Share on other sites

Thanks for the hint. However, the argument $small seems to refer to the abbreviated lists like category views, not the paginated list of all articles (the "standard" blog view). I did this and it doesn't have any effect:

   <?php 
    foreach($posts as $page) {
        $pagecount = count($posts);
        if(!$small) {
        include('./post.php'); 
        } else {
        include('./post-list.php'); 
        }
    }
    ?>

While this works, albeit only if there are multiple posts on a paginated page:

    <?php 
    foreach($posts as $page) {
        $pagecount = count($posts);
        if($pagecount == 1) {
        include('./post.php'); 
        } else {
        include('./post-list.php'); 
        }
    }
    ?>
 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...