Wordpress Block Theme Query Data - php

I have been using the Twenty Twenty-Two theme in Wordpress that is running on AWS lightsail multisite WP environment. I have found it easy enough to layout content using block editor.
Now I want to query data from the database (for now just want to use the Wordpress database where I added a table) and display that information.
I see tutorials for older versions of WP but I can not find any resource that provide much guidance on this. What I know thus far is I can not simply add php code to a page or post.
Please help. Frustrated at this point. Seems like this would be common task.

The question of "[how to] simply add php code to a page or post [in WordPress]" is not easy to answer because there are multiple ways you might approach it.
I recommend you search for phrases like
"add php WordPress functions.php"
"Why Child Theme custom php WordPress"
"how-to simple WordPress plugin custom php"
Good luck!

Related

Can I use HTML based theme in wordpress

I've been trying to create different themes in wordpress but it seems difficult to me as it requires some core functions of Php which I am unable to understand. Now I want to ask the question in details whether we can convert HTML theme to wordpress theme? I know that every theme is made in HTML but what If I make a theme in HTML/CSS or even bootstrap. How to integrate it with wordpress Posts and Pages thing? How can I tell wordpress that when a user adds a post through wordpress, it should go here or wherever? I think the question is vague but I myself is confused. Please do let me know if you understood! Thanks
You will need a combination of PHP, HTML, and CSS (at the least) to create a WordPress theme. Luckily, the PHP requried for a basic theme is pretty simple. I'd like to refer you to: https://www.siteground.com/tutorials/wordpress/wordpress_create_theme.htm . It gives a basic overview on theme development where the PHP isn't too involved.

Wordpress plugin using existing theme

I am building a plugin for the first time and I have setup my rewrite rules to call a PHP file I have located in my plugin folder and this is working but all I have it output just now is "test"
I wanted to ask, is there is a way of pulling in the existing theme and using this as the basis for the page, then I can have my plugin just output the page content area so to speak.
My plugin is quite big in terms of the amount of data it handles so I would like to be able to use a menu link to the aforementioned file and this file can then output all the sub pages of content but still using the default theme (theme I have made) and fill the content area only is this possible and if so is there anything to explain this already available because I couldn't see it.
Any help with this would be much appreciated.
Edit: I have tried including a file from my current theme but this will give me a 500 error so I assume its not as simple as this.
Have you thought about using custom post types for your plugin content rather than relying on custom tables and separate code?
Other than that, you could use a shortcode (just one) and have users insert that into a regular WP page, the shortcode then displays all of your various plugin stuff.
It's hard to be more specific without understanding why you've done it this way.

Modifying wordpress to create a customized CMS

I am working on moving a normal HTML website to Wordpress for a client. It's a simple website with a lots of images and HTML text. The idea is that client should be able to modify contents of website through the simple CMS without actually looking into code.
While doing analysis I came across some roadblocks like
Problem: If I want to modify text/ image for Header or footer in wordpress, I will need to do it in PHP code.
Solution: Create a customized header/ footer update tab. Modify database to store these contents and modify PHP code to directly read the data from database.
Problem: Wordpress provides a set of widgets (blogrolls catergories etc.), I need more like Latest News.
Solution: Modify PHP code and datbase, basically create your own widget.
Problem: There are a lot of static HTML pages which are linked from one page to another.
Solution: I don't see any way in wordpress to create static HTML pages which among which we can create links from one to another.
Solution: Create a new interface where user can create HTML pages/ plain text content. This will return a link which can be used to provide hyperlinks in another page.
My query is: Are the solutions mentioned above correct? The problems mentioned look very common, so is there a tried and tested way to solve?
Edit: User (Client) want to use wordpress. Just wanted to make sure here that Solutions I am thinking about are correct. So would like to have suggestion from someone who has already worked on Wordpress and solved the problems like I have mentioned. Do not want to reinvent the wheel.
I've worked a lot on a Wordpress-base white-label CMS, so I think I can help you in some ways.
First of all : always remember the real power of Wordpress is its community and its plugins base (that you can access directly from wordpress admin)
Problem: If I want to modify text/ image for Header or footer in
wordpress, I will need to do it in PHP code. Solution: Create a
customized header/ footer update tab. Modify database to store these
contents and modify PHP code to directly read the data from database.
If you want to have a fully customisable appearance, I suggest you to start from a theme like Consctructor. This is a theme with a whole admin panel for simple appearance editing. The code is far from perfect but this is a good start.
If you just want to manage the content of header / footer, you can do it via Menus / Widgets / Links, but only if your theme is designed for that. For example, a lot of good theme allow you to add widgets in footer, then you can construct your footer with only a few drag-n-drop in the Appearance/Widget menu. For header image, the default theme (Twenty-Twelve) provide an header panel where you can upload a new image.
Problem: Wordpress provides a set of widgets (blogrolls catergories
etc.), I need more like Latest News. Solution: Modify PHP code and
datbase, basically create your own widget.
Yes you can create your own widgets for specific needs, but I suggest you always start from an existing one. There is a lot of plugins providing you dozens of widgets. Explore that before reinventing the wheel.
For your specific case, a 1s google-search returns me this plugin.
Problem: There are a lot of static HTML pages which are linked from
one page to another. Solution: I don't see any way in wordpress to
create static HTML pages which among which we can create links from
one to another. Solution: Create a new interface where user can create
HTML pages/ plain text content. This will return a link which can be
used to provide hyperlinks in another page.
No, use the pages. Wordpress Pages are static content and this is editable, and for each page ou have a permalink. If Pages aren't good for your job, you can consider creating a custom type (or install a plugin that create a custom type).
Wordpress themes can be made to accept images and stuff like that.
The are ample wordpress widgets to do just that. Just be sure to find the right one.
I don't understand this one. You can create any amount of wordpress pages, and to link between them is easy. If you want your files to end in .html, simply enable permalinks and specify that option. It's very easy.
Reinventing the wheel sometimes is good, possibly even good for you (Given patience and time). Nothing is prepackaged to do everything for you, hence these are times when you need a custom build.
Anyways, CMSes don't come as a multipurpose, all-in-one package that solves your programming woes and turns everything into a point-and-click solution. Every CMS is unique, designed to serve a specific purpose. Others general purpose, others for blogs, others for very simple sites.
If you don't find anything native that fits your needs, find the right plugin for the job. If you cannot find anything at all, then might as well build a custom solution, or build on top of an existing resource. Innovate

Simple way to add "the loop" from Wordpress into any html/php template (that is not made for wordpress)

im looking easy steps for convert any html/php template into a very simple wordpress theme for personal use. I have a site, in there i want news at the begining using the wordpress interface, i worked a lot with wordpress and i made some themes, but modifing already made ones, so i didnt care a lot about the code.
So, lookin in internet i dint found a good step by step tutorial in order to create a simple theme in wordpress from 0. Remember that i dont need sidebars, widgets and soo, i only need "the loop", or, the last 3 post made.
It's as simple as installing wordpress correctly and then including the wp-blog-header file into your pages. Doing so will give you access to all of WP's functions.
require('/path/to/wp-blog-header.php');
$posts = get_posts('arguments');

Wordpress pull Blog Post

I'm designing a theme for wordpress. I need advice on how I would construct it.
At the bottom of my Frontpage/Home I will put a snippets (a title and a short description of blog post) of what is new in my Blog .
Preview:
Question:
What approach should I use? I can make the bottom page widget ready and will just use widget or will use PHP to pull details in my 'blog' page (I dunno how to do it php, a link would be useful)
what is the proper approach? I'm designing it for a client. My concern is If I would make it widget ready, client would have to install the widget. If I would do it on PHP, (I have no resource and idea in doing that )
Thanks!
You'll need to know some PHP and JavaScript if you want to make a WP theme from scratch. Otherwise I would suggest to modify an existing one.
Here is the theme development help from WP.
You'll have to run a loop, in which you'll retrieve the posts from the database (Wordpress handles that) and show them as needed.
The Loop In Action and
Building Custom Wordpress Themes
Hope that helps

Categories