WordPress - Get all of current page's queries information - php

Okay... so here is what I'm trying to do. Basically all of the components that make up any particular page on a Wordpress site, I need to be able to grab the query that WP is running to grab the data for that particular area of the given page. So, if we have page A, let's say it has a top navigation, main content section, and footer. Each of these three areas have content that is pulled from the database. I need a generic way to say on page X I want to know what queries have been ran to generate all of the content pulled from the database and displayed on the page.
I feel like the key is to properly use https://codex.wordpress.org/Class_Reference/WP_Query to get the data I need.
Any thoughts on how I could go about this?

Related

Multiple pages for custom_post_type posts

I have a custom_post_type that creates the posts for campaign_posts, they are displayed singularly on the front-end of my site with the page template single-campaign_posts.php.
Now, what I am trying to achieve is;
single-campaign_posts.php displays the post (already taken care of)
A second page that will display a frontend editor of the post (contents of this page is already taken care of
A third page that will display analytics for the post (again, the contents of this page has been taken care if)
So when a post is viewed they can click a link within single-campaign_posts.php to display either the analytics page or edit page. The pages that are linked to must be;
able to recognize that the contents of that page relate to the post
the URL slug is for example if the post was /campaigns/dummy-post would be /campaigns/dummy-post/analytics for the analytics page and /campaigns/dummy-post/edit-campaign for the edit page.
I have tried using nav tabs to do this and it works, however, I would rather have the contents on separate pages.
I hope this enough information to obtain my goals in this. I cannot see much point in adding details of the functions.phpor single-campaign_posts.php but if they are required then please let me know.
I hate seeing posts like this, but I have come up empty on searches for a solution. In its very basic form, I need three pages that all relate to the single post.
Thank you for your time and if you need more information please let me know.
I have found the solution to this now.
The solution was to use Rewrite API/add rewrite endpoint as seen Rewrite API/add rewrite endpoint
An example is posted in this question - Create Post tabs in single-{content-type}.php with Custom Field values

How to scrape my own site? (php/wordpress plugin)

I am trying to make a table on my website display images and text based on the data of another hidden table that is easily pasted into the website.
I feel like this should be pretty simple but I do not know where to begin looking. I dont know if this is similar to scraping another site or if there is a wordpress plugin where I can make a certain input display certain things in a table.
Thanks
EDIT - Forget scraping, I just want to display something based on something I paste in that is hidden.
I have a stylized table and a table that with the data that will be pasted in. I want the data in the pasted in table to show in the stylized table, but if the data is, for example "123", I don't want it to display "123" but a certain image instead.

How to "creating new page" works in PHP?

Page creating in PHP: I'm trying to learn how to make a cms but I couldn't understand something. For example in Wordpress when you click "create a new page" button what is happening at the backside? For example now I don't have any page.
I want to create these pages dynamically:
Home
About
Contact
After I want to add this pages in my menu. What is the best way to do that?
Questions:
Should I create a new php file to do this or just get data from my database which belongs to each page?
How I add these pages in my menu dynamically ?
What is htaccess? I couldn't understand that exactly it does relating the the processes of the files.
There are tutorials on internet but they always show how to get articles from database. When I have another item (for example a slider) I need a real page.
Can somebody suggest me a simple tutorial, or provide a clear explanation which explains the logic simply.
I have created something similar. This is how I did it (may not be the best way but it is certainly the easiest).
Create a template file and insert tags (!Title!, [[Title]], etc) where you want the new pages data to be inserted.
When creating a new page, read the contents of the template and replace the tags with the data submitted (I used titles, desc, h1, etc but this can also be achieved through a simple content function)
The user selects/creates the directory using mkdir()
All this is then stored in DB ready for the user to navigate to.
You can then use the DB entries to build a navigation menu

For Google crawling purposes: Single PHP pull-page, or individual pages for each different item?

I am creating a site and want to have individual pages for each row in a database table. The information on each page is fairly useful and comprehensive, and it would be really nice if Google could index them.
My initial thought was to just create a single PHP template page and pull the correct information for whatever the user is looking at, but my fear is that search engines won't be able to index all of the pages.
My second thought was to batch-create/automate the process of creating the individual pages as html files (for the 2000+ rows in the table), because then I would be guaranteed that they'd be crawled. However, if I ever needed to make a change to the design, I'd have to re-process them all. Kind of a pain...
My final consideration was to just pick a page in my site and list all of the possible php pages in a hidden div, but I wasn't sure if search engines can index from that. I assume they just pull from the HTML, so it'd be able to find it, right?
Any suggestions? I would love it if I can just create a single page that populates based on what they user clicks, but I want them to be indexed.
Search engines can index dynamic pages so using one PHP file to create thousands of unique product pages will be fine for SEO. After all, each page/product will have a unique URL and will be seen as a unique page as a result. All you need to do is link to your product pages within your website and/or submit an XML sitemap so you can be sure they are found and indexed.
By linking your pages, I literally mean link to your product pages. Search engines find new content primarily through following links. So if you want your product pages to be found you need to link to them. Using form based search is not a good way to do it as search engines generally don't play to well with forms. But there are lots of way to make links to your pages including HTML sitemaps and product category pages which then can link to products in that category. Really, any way yo u an get a link to your product pages is a good way to help ensure they are found by the search engines.
You don't have to post links on invisible DIV!
Just create the page and have parameterized content fetching.
You can include the pages in the XML sitemap and submit to Google or you can include your page urls in the HTML sitemap too.

Publish blog on front page of a website

I'd like to show my latest blog post as a teaser on the front page of my personal website, in a div. Ideally it would even have a word limit -- maybe the first 100 words and then an ellipsis and link to the actual blog along with date and time.
Additional my blog is not attached on my website (so that I can't access it's database). My blog may be saved on like: blogspot.com etc..
I assume that everything is self-coded, so we don't have any abstractions or something. If you run a blog and a website there's probably some database or two. You'll seed to write SQL query that gets latest post from posts table and run it somewhere inside you website's code. If you have that data use field storing post's date, time and full text and extract 100 words [non trivial problem if you have HTML inside] and display them in a proper template file of your website.

Categories