Support » Theme: Customizr » Add a specific page before featured pages

  • Resolved side2side

    (@side2side)


    Thanks for this great theme and for all the support you guys provide! You are great!

    Problem: I’d like my front page to display a specific page (page_id 205) above the featured pages and then (under the featured pages) the posts.

    So my intended front page structure is: 1) page 205; 2) featured pages; 3) posts.

    Now I’ve checked a lot of snippets (thanks they are great!) and other solutions. The best I was able to get from previous solutions is here below (I’m pretty new year…). The problem is that with the solution below I display not only page 205, but also the posts before the featured pages (while I’d like to have the posts under the featured pages). Can you provide any help? Thanks in any case!

    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='205'; // 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
    }
    
    //we hook the code on the wp_head hook, this way it will be executed before any html rendering.
    add_action ( 'wp_head' , 'move_my_fp');
    function move_my_fp() {
        //we unhook the featured pages
        remove_action  ( '__before_main_container', array( TC_featured_pages::$instance , 'tc_fp_block_display'), 10 );
    
        //we re-hook the block. Check out the priority here : set to 0 to be the first in the list of different actions hooked to this hook
        add_action  ( '__after_main_container', array( TC_featured_pages::$instance , 'tc_fp_block_display'), 0 );
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Theme Author presscustomizr

    (@nikeo)

    Hi side2side,
    This snippets gives some leads but is way too complicated for your need.
    Here’s a simpler solution :

    function display_a_page_before_fp(){
       if ( !tc__f('__is_home') )
            return;
        //gets the page object from your database
        $mypage = get_post(205);
        ?>
        <div class="row-fluid">
    	    <div id="content span12" class="article-container">
    	    	<article>
    		    	<div class="entry-content">
    		        	<?php echo apply_filters('the_content' , $mypage -> post_content ); ?>
    		    	</div>
    		    </article>
    	    </div>
    	</div>
        <?php
    }
    //adds the page before featured pages. Note the priority set to 0 in the action declaration => will tell WordPress to add the action before any other (featured pages have a priority of 10 on this very same hook)
    add_action  ( '__before_main_container', 'display_a_page_before_fp', 0 );

    Hope this will help!

    Thread Starter side2side

    (@side2side)

    It works like a charm! 🙂
    Thanks a lot Nik for your theme (super!) and for all your support in the forum and website!

    Thread Starter side2side

    (@side2side)

    P.s.

    I noticed a potential issue, and since I lost 40 minutes to figure out what was the problem, maybe it can be of some help for somoeone.

    The snippet that Nik was so kind to post here above works in a perfect way if you have some text in at least one post. If you do not have any post at all, also the page you would like to show in the front page (in my case p 205) will not be displayed in the front page. I do not know why and how to solve it; just triyng to help to identify the issue if anyone else will have this problem

    Thanks again to all of you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Add a specific page before featured pages’ is closed to new replies.