0

/I have few pages in my wordpress site which should contain some php code. For example news page.

In my front-page.php I have a while which loops trough all posts and prints few news.

In my news site I want to do the same.

I have already tried using

<?php /* Template Name: news */ ?>

But this is only the template, so only my html works here, php while did not output any data.

What is the best approach to achieve this (as simple as possible) ?

EDIT:

In simple words, how to create a static php wordpress page.

Thank you!

  • Are you trying to add the PHP to the template file itself, or in the content editor? – WebElaine Mar 27 '17 at 20:25
  • PHP code should be between php tags. use get_header and get_footer functions. – MahdiY Mar 27 '17 at 20:30
  • @WebElaine Imagine you have your web site, in the navigation you press on the "News" . And you open news.php from your template directory and display it in your site. In the same way that you create e.g front-page.php . The templating thing i wrote bellow is not what i am looking for it was just an example of me not finding the right way (in a way) :))) – Giedrius Mar 27 '17 at 20:31
  • @MahdiY which planet are you from, did you even read the question ? – Giedrius Mar 27 '17 at 20:33
  • It sounds like you may be looking for WP_Query or something similar, to grab a group of posts and display them within your news page template. – WebElaine Mar 27 '17 at 20:53
1

MahdiY just explain that you can use PHP in your template like that

<?php
/*
Template Name: news
*/

get_header();
?>

    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">

            <?php
                echo "This is PHP";
            ?>

        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_footer(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.