• I’ve figured out that when you add a new page in the control panel it adds a row to wp_posts in the database. So far so good. How do I access that page in my php file?

    For example, page one is, in my case, “wp_posts” and “id” 13. How do I tell my index page that is the page I want displayed?

    Or am I doing this wrong? For a static set of pages, called index.php, aboutus.php etc. how do I tell the individual pages which part of the database to use?

    Thanks
    Charles

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi

    While what you are describing will work, you are thinking PHP centric and not WordPress centric. WP has its own built in methods to retrieve almost anything from the DB, to save a lot of custom programming time.

    For starters see
    https://codex.www.ads-software.com/The_Loop
    https://codex.www.ads-software.com/Pages#Creating_Your_Own_Page_Templates
    https://codex.www.ads-software.com/Template_Tags/query_posts
    https://codex.www.ads-software.com/Template_Tags/get_posts

    Thread Starter charles_i

    (@charles_i)

    Thanks for the answer – I’m not describing how to make it work – I’m asking HOW to make it work. I’ve read the pages you’ve posted and they are all bout coding for a blog. I am working on a community website so there will be a Home Page, About Us, Contact, Minutes of Meetings – AND a blog. But the blog is only ONE page of the site – the rest are static pages.

    On the Pages Codex page it says WP can be used as an excellent CMS tool for static pages. I have read all of the posted tutorials and none of them mention HOW to do this – they all talk about things like the Loop which are for setting up a blog.

    All I want to know is if I create a page in the control panel (or whatever it’s called) how do I make that page appear live? I have to put SOME PHP code on a page – like index.php, correct? I know how to put the header, sidebar and footer code in so it will show up – what do I put in the index part if it is NOT a blog an does not need loops, comments or any of that stuff?

    Thanks
    Charles

    Hi – You don’t need to do anything to make a page live. It is live the minute you publish it. ( I use WP 95% for websites not for blogs by the way)

    If by live you mean “added to the Nav bar”, in the header of your theme investigate using wp_list_pages to display the Nav as every time you create a page it automatically adds it to the Nav. If its already in your theme header, read up and learn how to use it, and about menu page order to control the order in which pages appear in the Nav bar.
    https://codex.www.ads-software.com/Template_Tags/wp_list_pages

    There is no difference between a page and a post at all, except an indicator in the database that a post should be considered as a page not a post. You can’t add a page to index.php because a page does not exist anywhere as a disk file – it is just an entry in the database. Header, sidebar and footer code exist as physical files on disk – not pages.

    Have you found the settings Admin / Settings / reading which allow you to make a static page your home page? It all starts from there.

    Feel free to ask further questions.

    I forgot to add

    Pages do in fact use the WordPress loop. It just generally executes only once. However if you use a WP page as the basis of a custom posts page, for example all the posts in my Laptop category to display on the page called Laptops, then the loop in fact executes once for each post being displayed.

    Pages are very versatile and can be used in many ways. The way I conceptualize a page is, it represents an entry on the site Nav. Within that I can use the page in many ways.

    Thread Starter charles_i

    (@charles_i)

    Thanks for your help. Yes I set the page in Admin / Settings / reading. Thanks for clearing up that the loop runs once on a Page.

    OK a page is an entry in the database – I’ve discovered that, but when you say “you can’t add a page to index.php” how else do you create a home page for a website when the home page is always index.php? I’ve tried creating a new page and publishing it but it doesn’t work. If I view my theme Appearance it’s there but with no content because I’m back to wondering what php I need in index.php to generate the content created in Add New Page. I removed all of the templated php code because I don’t want all the blog features. Maybe I should just put the loop back in.

    I think there’s something fundamental I’m not getting at all here. I noticed today there are quite a few books out on WordPress. Maybe you could recommend one that specifically deals with creating a website – not a blog.

    Thanks
    Charles

    Hi

    Here is a free WP theme called SimpleCMS Everything blog-related has been stripped out of it. You can study how it is put together and see how WP can be used as a CMS.
    https://pixopoint.com/simplecms_theme/

    the home page is always index.php?

    So you know, throughout WordPress the only file that is EVER running in index.php. Every other file is included by calls from index.php. I don’t mean the index.php in your theme folder (that too is included) but index.php in the root WP folder. That is the point of permalinks – they hide that the actual URL of everything is
    https://mydomain.com/mysite/index.php?p=234

    Your idea that you have to do something with index.php is incorrect As long as you insist that, you will not begin to understand how WP works. It is a FRAMEWORK and most of the dirty and hard stuff is already done for you. The cost of the ease is you have to find out the rules and architecture of the framework

    Here is another useful document
    https://codex.www.ads-software.com/Template_Hierarchy

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How do I code a static Page php file?’ is closed to new replies.