Following this discussion in the Customizr theme support forum, here’s a simple piece of code that will allow you to add any post or page before your post or page content in the Customizr WordPress theme.
The following snippet will add the content on your front page and before the featured pages.
You can change the condition ( ! tc__f(‘is_home’) ) and the hook to target a new context and a new location in any pages/posts/archives.
function display_content_before(){ if ( !tc__f('__is_home') ) return; //gets the page object from your database $mypage = get_post(205); //<= set the id of the page or post you want to insert ?> <div class="row-fluid"> <div id="content" class="article-container span12"> <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_content_before', 0 );
Additional resources :
- How to customize the Customizr WordPress theme
- Twitter Bootstrap grid
- WordPress Hooks API
- Exemples of Customizr customizations with add_action() WordPress function
- Understanding action and filter hooks in WordPress.
16 thoughts on “Add a specific page or post content in another post or page”
Sorry, I’m new with WordPress, but can someone explain how to use this? I have multiple pages, and I wanna post something in one of my specific pages (based on specific category). But I still want my homepage show all of my post regardless which category it is, just like news feed. Thanks
Hi,
It might be easier if your post your site url and your requirement in the support forums here: https://wordpress.org/support/theme/customizr
Hi, thanks for these helpful snippets! However, I created a page with ‘Page Builder by SiteOrigin’ and tried to use this method to place it on the front page. Unfortunately all of the CSS formatting from the gets removed when it is displayed. Does anyone know how to stop this happening? Thanks
Hi Dave,
The developer team handles support for Customizr at https://wordpress.org/support/theme/customizr and for Customizr-Pro at http://presscustomizr.com/support/. Please post your query there with a link to your site.
Hi Ashley,
The developer team handles support for Customizr at https://wordpress.org/support/theme/customizr and for Customizr-Pro at http://presscustomizr.com/support/. Please post your query there with a link to your site.
I used the above snippet to move the content of the page above the feature pages… but now I want to remove it from below the feature pages (because it’s now showing twice on the page)… what do i add to remove it from below?
Hi, I need to add a post to one of my pages but I don’t get where I have to paste the snippet?
Hi Manuela,
You’ll want to read this guide on how to customize the Customizr theme to start customizing your theme.
If you need further assistance, then you can ask for help in the Customizr support forum.
Cheers.
Hi Nicolas
I hava a question:
I need to have the last posts on the home page but I also need to have a page called “news” that display the last posts.
In Wordpress if I select “Your latest posts ” in Front page displays setting than I cannot assign a page for last posts.
how can I do that?
Thanks very much
Nicolas, firstly thanks for such an awesome theme is one of the best I have come by!! 🙂
I have been searching round the code snippets and hooks on here and am having trouble finding specifically what I need…
Could this snippet be modified to allow me to do the following.. (or would there be a better one for it?)
I have previously used custom page templates with ‘query_posts’ (
) to allow me to have a page with its standard content showing first, and under that shows all full posts from ‘Category A’ if the page title is ‘Category A’
Hopefully that makes sense, and hopefully you can assist. Regards Kade.
(Sorry code snippet messed up) what it should have said in it was “query_posts(‘category_name=’.get_the_title().’&post_status=publish’);”
Hi Kade, that makes perfectly sense to me 🙂
I would hook a callback function on the “__after_main_container” action hook.
The callback function could for example use the get_queried_object() wp function to get the current post categorie(s).
Then, once you have the categories, you could retrieve the post lists using the get_posts() wp function with the categories as arguments, and loop on this posts list to display the HTML markup.
Note :
1) pages can’t be assigned to a taxonomy (category or tag) in WordPress, I think you are talking about posts.
2) query_posts() should never be used in WordPress. It creates additional queries and can lead to serious inconsistencies (widget bugs for examples) throughout your website.
Hope this helps!
Hello, I would like to add specific page to specific category instead of front page, is there a hook for that purpose? Thanks in advance!
Hi,
Instead of
You might want to use the is_category() conditional statement.
More about this here : http://codex.wordpress.org/Conditional_Tags
Hope this helps!
Thanks for this snippet, it’s almost exactly what I’m looking for.
Is there a way to hook featured pages to a specific spot in the middle of the static front page? Or maybe somehow break a page in two and hook it before and then the second part after FP?
I figured it out, it took me a while to realize I can add custom page with above code and use the built in settings to have a static page under the featured area.
Thanks for such a nice and customizable theme 🙂