0

I am trying to build a one page theme using WordPress. My current loop looks like that:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<h2>
  <?php the_title(); ?>
  </a>
</h2>
<div class="entry">
  <?php the_content(); ?>
</div>

<?php endwhile; endif; ?>

I want to display only a specific page, for instance the one with id 5. How can I realise it?

3
  • have you looked at WP Query ? Commented Jul 21, 2018 at 16:05
  • I don't quite get what to change... I haven't really worked with php so far Commented Jul 21, 2018 at 16:10
  • Related: wordpress.stackexchange.com/questions/46582/… Commented Jul 5, 2024 at 9:22

2 Answers 2

1

Can't use just create a page in the backend and set it as a static front page using "Settings > Reading > Front Page displays"?

If you want the page to be included in your theme you could create a page template and then create a page in the backend and use this template there.

https://developer.wordpress.org/themes/template-files-section/page-template-files/

But if you're just starting out in learning php, I wouldn't recommend you to jump straight into WordPress development. I would learn php first. Otherwise you can very easily get confused and at some point you will not be able to differentiate between php and WordPress specific functions, variables, conventions, ... .

Sign up to request clarification or add additional context in comments.

Comments

0

Remove the if... while line (and the closing one at the end) and add:

$page = get_post( 5 );
setup_postdata( $page );

See the Codex entry: https://codex.wordpress.org/Function_Reference/setup_postdata

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.