I am using this code to bring the content out of the page.
<?php
$page = get_page_by_title( 'page-title' );
$title = $page->post_title;
echo "<h3>" . $title . "</h3>";
$content = apply_filters('the_content', $page->post_content);
echo $content;
?>
Now, i want to get the content and title by using page ID.
If any one has the answer?
You can use the
get_post()
functionPer your comment:
I bolded that word because if this is the case there’s a very simple solution, but there are many ways to reach it.
Option 1:
If you’re familiar with the WordPress Template Hierarchy you’ll know you can create a PHP paged called
front-page.php
. Then you can create 1 single page underPages
, once that’s done you can go toSettings -> Reading
and click the radio button which allows you toYou can then select the page you created. This will automatically use the
front-page.php
template versuspage.php
.Option 2:
You can copy your
page.php
template and rename it to use a pages slug. For instance, if I create a page called “Contact Us” WordPress will automatically make a slug that looks likecontact-us
which is part of the web URL to view the page. I can then copypage.php
and rename itpage-contact-us.php
so when you view the “Contact Us” page, it will automatically use this page template.Option 3:
Finally you can directly create a Page Template where you select it from a drop down in the Admin Panel when you create a new page. All you have to do is copy your
page.php
template file and call it whatever you want, something standard likepage_template-contact
or something of the sort. Then you can add this direct above yourget_header()
call: