• Resolved andryonline

    (@andryonline)


    How can I add a new page with the list of posts (the classic blog’s homepage)?

    Thanks a lot!

Viewing 15 replies - 16 through 30 (of 45 total)
  • Thread Starter andryonline

    (@andryonline)

    Exactly! 🙂

    Thread Starter andryonline

    (@andryonline)

    bdbrown, can you help me?

    bdbrown

    (@bdbrown)

    Been a bit busy with my day job here… I have a potential solution; I just need to test it.

    Thread Starter andryonline

    (@andryonline)

    Perfect, there’s no rush. Thanks!

    bdbrown

    (@bdbrown)

    OK, roll up your sleeves and get a cup of coffee (or a cold beer, whichever you prefer). This was a fairly lengthy answer so I posted it up on Pastebin. Give it a go and let me know if you have any questions.

    Thread Starter andryonline

    (@andryonline)

    I don’t know how to thank you! I’ll let you know soon… 😉

    Thread Starter andryonline

    (@andryonline)

    It works… great! 🙂

    And if I wanted to reverse the pages?

    And if I wanted to use two css files, one per page?

    bdbrown

    (@bdbrown)

    And if I wanted to reverse the pages?

    I would go back to the original home.php file and change the logic around so you end up with this:

    <?php if ( ot_get_option('blog-standard') == 'on' ): ?>
    	<div class="post-list group">
            <?php $i = 1; echo '<div class="post-row">'; while ( have_posts() ): the_post(); ?>
                <?php get_template_part('content'); ?>
            <?php if($i % 2 == 0) { echo '</div><div class="post-row">'; } $i++; endwhile; echo '</div>'; ?>
    	</div><!--/.post-list-->
    <?php else: ?>
    	<?php while ( have_posts() ): the_post(); ?>
    		<?php get_template_part('content-standard'); ?>
    	<?php endwhile; ?>
    <?php endif; ?>

    Then, the front page will always be displayed based on the status of the Standard Blog List and the other page will be the opposite. You can change them by switching the Standard Blog List option.

    And if I wanted to use two css files, one per page?

    You could enqueue another css file but they’re not page specific. You’d have to write a function or some other logic to determine which page you’re on and then enqueue the desired file. Doable but not something I would recommend. Far easier to just set the styles to target specific elements based on a body tag class; “archive” for the front page, “blog” for the other page. Just remember that whatever styles you apply to the front page will affect every other category, tag, author, etc. archive page.

    One way around that might be, in page-title.php, where you modified this section:

    <!-- if displaying the blog Home page or the static Front page -->
    <!-- query var 'error' is set in function 'my_front_page' -->
    <?php if ( is_home() || get_query_var('error','') == 'myfrontpage' ) : ?>
        <h2><?php echo alx_blog_title(); ?></h2>

    Change it to add an empty div with an id on the front page so you can identify it:

    <!-- if displaying the blog Home page or the static Front page -->
    <!-- query var 'error' is set in function 'my_front_page' -->
    <?php if ( is_home() || get_query_var('error','') == 'myfrontpage' ) : ?>
        <!-- if on the static Front page add an unique id -->
        <?php if ( get_query_var('error','') == 'myfrontpage' ) : ?>
            <div id="my-front-page"></div>
        <?php endif; ?>
        <h2><?php echo alx_blog_title(); ?></h2>
    bdbrown

    (@bdbrown)

    OK, never mind about page-title.php. The logic is right but that’s the wrong place to do it; it’s too far down in the DOM. Working on another idea.

    bdbrown

    (@bdbrown)

    Here’s how to handle identifying the front page:
    1. Copy header.php to your child theme
    2. Locate this line near the top of the file:

    <div id="wrapper">

    3. Change it to this:

    <div id="wrapper" <?php if ( get_query_var('error','') == 'myfrontpage' ) { echo 'class="my-front-page"';} ?> >

    Now, when the query is running on the front page, it will add a class to the wrapper and the wrapper div will look like this;

    <div id=”wrapper” class=”my-front-page”>

    You can target the elements on that particular page using #wrapper.my-front-page.

    Thread Starter andryonline

    (@andryonline)

    I would go back to the original home.php file and change the logic around so you end up with this:

    <?php if ( ot_get_option('blog-standard') == 'on' ): ?>
    	<div class="post-list group">
            <?php $i = 1; echo '<div class="post-row">'; while ( have_posts() ): the_post(); ?>
                <?php get_template_part('content'); ?>
            <?php if($i % 2 == 0) { echo '</div><div class="post-row">'; } $i++; endwhile; echo '</div>'; ?>
    	</div><!--/.post-list-->
    <?php else: ?>
    	<?php while ( have_posts() ): the_post(); ?>
    		<?php get_template_part('content-standard'); ?>
    	<?php endwhile; ?>
    <?php endif; ?>

    Then, the front page will always be displayed based on the status of the Standard Blog List and the other page will be the opposite. You can change them by switching the Standard Blog List option.

    It works! 😉
    But there’s a problem: in the “default theme blog layout” (now first page) featured post doesn’t work. Instead in the “standard blog list” page it work. It’s strange!

    Thread Starter andryonline

    (@andryonline)

    There’s another problem: in the “default theme blog layout” (now first page) the primary/secondary sidebar settings don’t work.

    Edit:
    Editing all types of page (home, single, archive, etc.) it work. Editing only home page, it don’t work.

    bdbrown

    (@bdbrown)

    To remove the Featured Image from the Blog page, edit the home.php file and remove this line:

    <?php get_template_part('inc/featured'); ?>

    Then you’ll need to copy archive.php to your child theme and find this at the top of the file:

    <div class="pad group">		
    
    	<?php if ((category_description() != '') && !is_paged()) : ?>

    and add the code to display the Featured Posts on only the Front page:

    <div class="pad group">		
    
    <?php if ( get_query_var('error','') == 'myfrontpage' ) : ?>
    	<?php get_template_part('inc/featured'); ?>
    <?php endif; ?>	
    
    	<?php if ((category_description() != '') && !is_paged()) : ?>

    Then copy the parent theme file /inc/featured.php to your child theme /inc/featured.php and find two lines that begin with this:

    <?php if ( is_home() && !is_paged() && ( ot_get_option('featured-posts-count')

    and change the “is_home” argument to “is_archive”:

    <?php if ( is_archive() && !is_paged() && ( ot_get_option('featured-posts-count')

    What you’re going to have to remember, and it’s going to be more complicated the more customizations you make, is that your Front page is using the Archive page layout, and your Blog page is using the Home page layout. If you change the sidebar layouts on those page types, that will affect your Front and Blog pages respectively. However, the Archive page sidebar layout will also affect all category, tag, author etc. pages, and there is no easy fix for manipulating the sidebars based on the specific page.

    Also, your configuration is a major change from the standard way the theme operates. Unless you’re making a lot of notes or have some extensive documentation, you or someone who comes after you are going to find it very difficult to understand the configuration at some point in the future.

    Thread Starter andryonline

    (@andryonline)

    First, thank you! You’re right, maybe I’ll use only one layout (standard blog list). I think about it and let you know.
    The instruction in your last post, are to “default theme blog layout” as the first page or “standard blog list layout” as the first page?

    bdbrown

    (@bdbrown)

    It doesn’t matter which layout the Front page is using. If you don’t make the code modifications as described above then the Featured Posts will always be on the Blog page, and never show up on the Front page. The Featured Posts are independent of the page layout.
    And I wasn’t trying to suggest that you only use one layout. The setup you are wanting will work fine. I’m just saying that, after it’s done and you haven’t looked at it for awhile, or if someone else needs to work on it, you should have some documentation as a reference for the changes you’ve made.

Viewing 15 replies - 16 through 30 (of 45 total)
  • The topic ‘Add a new page with the list of posts’ is closed to new replies.