• Resolved Ultimate Peter

    (@peastvoldqbservicesnet)


    Apologies if this question has already been answered somehow.

    (WordPress: you need to make it easier to search these support posts, specifically for one theme / plugin. I can’t sift through these 163 pages of answers)

    Anyway, I have created a static front page for my site here: https://qbservices.net

    Now, the only thing missing is:
    Under the placards I have setup, I would like the blogroll from the built-in front page to show up (you know, the format with listed blog posts and alternating left & right circles).

    Is there a shortcode, or a piece of PHP I can stick in (with php-on plugin) that will make the beautiful blog-roll from the standard front page end up after my custom content on the front page?

    Thanks much!
    Peter

Viewing 15 replies - 1 through 15 (of 42 total)
  • It’s probably easier to do it the other way around. That is, customize your site to show the blog posts on the front page and then insert your content before the posts.

    I was working out ways to do this and at first thought of using the ol’ widget approach, but you don’t want a whole load of possibly frequently-updated content sitting in a widget.

    You also don’t want a whole load of content sitting in php, where it’s harder to update, version, preview, etc.

    So I came up with the idea of inserting a page’s content before the blog posts instead.

    I presume that for your current front page, you have set Customizr up to show a static page on the front page. So you already have a page of content that is your front page.

    Do the following :

    1. Change your current static page’s title to home and set the slug to home;
    2. In Settings > Reading (not in Appearance > Customize *) , set the front page to show your latest posts;
    3. Put the following in your child-theme’s functions.php**:
      add_action  ( '__before_loop', 'add_home_page_before_posts');
      function add_home_page_before_posts($path) {
      	if ( is_home() ) {
      		$post = get_page_by_path( '/home' );
      		$content = $post->post_content;
      		echo $content;
      	}
      }
    4. Use a redirect plugin (e.g. Eggplant 301 Redirects — I’ve not used it myself, but it gets good ratings and seems well-supported) to permanently redirect your page called “home” to your real home/front page. (That is, redirect from what will then be https://qbservices.net/home to https://qbservices.net/ ) You need to do this because, although it will not be on your menus or anything, search engines and the odd curious user might end up there by mistake otherwise.
    5. Tell me if it works for you.

    * Don’t use Appearance > Customize to change this because I think there’s a WP bug in there and have opened a ticket. Using it now might confuse things.
    ** You mention using a php plugin, but you really don’t need to do this. Read about customizing Customizr and you’ll see that it’s easy enough to do this yourself without a plugin.

    Polling d4z_c0nf and nikeo to see what they think of this solution, or whether there’s an easier approach. (I’m sure there’s a better, deluxe approach, which would take time to code, but this is relatively quick and easy.)

    What about something like this?
    Just add this snippet to your child-theme functions.php:

    add_action('__after_loop', 'my_blog');
    function my_blog(){
        if ( ! ( tc__f('__is_home') && 'page' == get_option('show_on_front') ) )
            return;
    
        query_posts('is_posts_page=true');
        if ( have_posts() && !is_404() ) :
            while ( have_posts() ) :
                the_post();
                do_action ('__before_article');
                ?>
                    <article <?php tc__f('__article_selectors') ?>>
                        <?php do_action( '__loop' ); ?>
                    </article>
                <?php
                do_action ('__after_article'); 
    
            endwhile;
            wp_reset_query();
         endif; ##end if have posts
    }

    Thanks! Glad you couldn’t see any holes in the solution I posted … yet ??

    Yup, that new code works too. It doesn’t give post navigation when you get up to the max posts per page, so it’s good if you have only a few posts.

    Just noticed ?? . Yep, is good just if you have few posts or if you don’t want the navigation in home :d . Whit this solution you can’t rever to the query var “paged”. You’re right.
    Honestly I haven’t digged in your solution, I just assumed it worked, in italian we say “Principio di Autorità” ??

    Better in English, though my wife would disagree ?? (Non comprendi btw)

    This is the dual solution:
    1) Set the front page to show your latest posts;
    2) Add the following code in your child-theme functions.php:

    add_action('__before_loop', 'my_home_page');
    function my_home_page(){
       if ( ! ( tc__f('__is_home') && 'posts' == get_option('show_on_front') ) )
            return;
        $page_id='7761'; // page id you wanna show on front above the blog.
        query_posts("page_id=${page_id}");
        if ( have_posts() && !is_404() ) :
            while ( have_posts() ) :
                the_post();
                do_action ('__before_article');
                ?>
                    <article <?php tc__f('__article_selectors') ?>>
                        <?php do_action( '__loop' ); ?>
                    </article>
                <?php
                do_action ('__after_article'); 
    
            endwhile;
            wp_reset_query();
         endif; ##end if have posts
    }

    3) Add this to your custom css:

    .home .page .entry-header{
        display: none;
    }

    @rdellconsulting
    Should be Authority Principle in english ..
    <<“If an expert says it, then it must be true,” is the basis of the Authority Principle.>>
    Listen to your wife .. she’s wise ??

    Thread Starter Ultimate Peter

    (@peastvoldqbservicesnet)

    Sorry, I could not test this until today, busy weekend.

    Yes! This worked brilliantly!

    You can check out the results: https://qbservices.net

    Now, I have my own custom navigation home, as well as a dynamic blogroll! And… It looks super seamless!

    I can’t thank you enough, and I think this code should definitely be shared, because I can imagine it would be quite useful to quite a few people with this theme!

    @ultimate Peter: could you tell us which code you used?

    d4z_c0nf:

    Honestly I haven’t digged in your solution, I just assumed it worked, in italian we say “Principio di Autorità” ??

    Senti il Principe dell’Autorità che parla a me dei Principii di Autorità! :-)))

    .
    .
    .
    (Before the mods complain about non-English, this means: “Look at the prince of authority telling me about authority principles!”)

    Thread Starter Ultimate Peter

    (@peastvoldqbservicesnet)

    Yes, after reading through the code, d4z_c0nf’s dual-solution made the most sense to me:

    -If this is the homepage -> show page number 7761.
    -Then list the blog loop.
    -Then play cleanup with CSS and remove the page name on the homepage.

    Worked like a charm!

    Bonus: I still get to easily edit my front page content using the editor

    @ultimate Peter: Great! Good to know ??

    @d4z_c0nf: OK, now I need to understand it better ?? I’m confused as to why you do all the __loop stuff in php when you can simply let Customizr do it with a blog on the home page.

    @electricfeet
    I don’t get what you mean, I leave Customizr handle the __loop stuff with a blog in the home page, as Ultimate Peter said, I just add another (customizr) __loop to display a page above the blog in home (and just if you decide to display your latest posts on front page).
    There’s a better way to achieve that? I’m opened to better solutions ??

    p.s.
    I’ve chosen this way just ’cause looking at his source page I’ve noticed that he was using a plug-in to build the page, otherwise I’d have suggested him the evergreen “add content after/before something”

    There’s a better way to achieve that? I’m opened to better solutions ??

    That was what I thought my first solution was: Tell Customizr to produce the blog posts and simply insert the required page above them.

    And isn’t what I do? ??

    You have the loop in your code; with a WP query; with action hooks. My solution uses the get_page_by_path() function, which goes straight to the db to get the contents of that page.

    As always, with WordPress, there are many ways to do what you want … this is in the spirit of the pursuit of the “ideal”, as a way of learning.

    Ahh, sorry didn’t get your point :D.
    Well the fact is that I wanted to keep customizr hooks, article selectors filters, and use customizr __loop (with its hooks and functionality). You can also wrap the content in an <article>, and so on.
    Your way is cheaper, I think, so, as usual, the choice will depend on the actual user needs ??

Viewing 15 replies - 1 through 15 (of 42 total)
  • The topic ‘Using Static Front Page: add blogroll to bottom?’ is closed to new replies.