Create Pages from DatabaseHow to create a php url redirection for nicer linksQuery the database after get_header() has been includedApply template to custom post typeHow to create custom layouts and static pages in themes for clientsCreate pages from MySQL databaseCreating custom page template from existing PHP siteStringing together content from different databasesNeed to create a custom page on a websiteNew entries to custom post type produce 404 on single view
Writing a letter of recommendation for a mediocre student
A drug that allows people to survive on less food
How use custom order in folder on Windows 7 and 10
I reverse the source code, you negate the input!
How does IBM's 53-bit quantum computer compare to classical ones for cryptanalytic tasks?
Why is there not a feasible solution for a MIP?
Social leper versus social leopard
Does a GFCI-protected bath light/fan unit need separate neutrals?
Can this word order be rearranged?
Late 1970's and 6502 chip facilities for operating systems
Is it impolite to ask for halal food when traveling to and in Thailand?
To what extent is it worthwhile to report check fraud / refund scams?
Guitar tuning (EADGBE), "perfect" fourths?
What can a pilot do if an air traffic controller is incapacitated?
Cut a cake into 3 equal portions with only a knife
Leaving a job that I just took based on false promise of a raise. What do I tell future interviewers?
What are these ingforms of learning?
Resolving moral conflict
Examples of "unsuccessful" theories with afterlives
What is the meaning of "heutig" in this sentence?
Is this a Sherman, and if so what model?
Transforming 2D points on to a regular grid or lattice
A high quality contribution but an annoying error is present in my published article
Hilbert's hotel, why can't I repeat it infinitely many times?
Create Pages from Database
How to create a php url redirection for nicer linksQuery the database after get_header() has been includedApply template to custom post typeHow to create custom layouts and static pages in themes for clientsCreate pages from MySQL databaseCreating custom page template from existing PHP siteStringing together content from different databasesNeed to create a custom page on a websiteNew entries to custom post type produce 404 on single view
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
i've recently decided to create a website with wordpress.
My goal is to a visualize data stored in a MySQL database. Each id in the database should represent one page on the website. From what i've read a custom post type or a custom page template should do the trick.
But my biggest problem is that pretty much all tutorials i've read or watched so far explain how to create a page for each "product" manually. My database currently has ~44.000 entries and there are more to come on a weekly basis, so this can't be the right way.
Is there some way to dynamically create a page based of a template after the user searched for it?
custom-post-types database templates mysql
add a comment
|
i've recently decided to create a website with wordpress.
My goal is to a visualize data stored in a MySQL database. Each id in the database should represent one page on the website. From what i've read a custom post type or a custom page template should do the trick.
But my biggest problem is that pretty much all tutorials i've read or watched so far explain how to create a page for each "product" manually. My database currently has ~44.000 entries and there are more to come on a weekly basis, so this can't be the right way.
Is there some way to dynamically create a page based of a template after the user searched for it?
custom-post-types database templates mysql
add a comment
|
i've recently decided to create a website with wordpress.
My goal is to a visualize data stored in a MySQL database. Each id in the database should represent one page on the website. From what i've read a custom post type or a custom page template should do the trick.
But my biggest problem is that pretty much all tutorials i've read or watched so far explain how to create a page for each "product" manually. My database currently has ~44.000 entries and there are more to come on a weekly basis, so this can't be the right way.
Is there some way to dynamically create a page based of a template after the user searched for it?
custom-post-types database templates mysql
i've recently decided to create a website with wordpress.
My goal is to a visualize data stored in a MySQL database. Each id in the database should represent one page on the website. From what i've read a custom post type or a custom page template should do the trick.
But my biggest problem is that pretty much all tutorials i've read or watched so far explain how to create a page for each "product" manually. My database currently has ~44.000 entries and there are more to come on a weekly basis, so this can't be the right way.
Is there some way to dynamically create a page based of a template after the user searched for it?
custom-post-types database templates mysql
custom-post-types database templates mysql
asked Apr 15 at 10:21
QUEQUE
61 bronze badge
61 bronze badge
add a comment
|
add a comment
|
2 Answers
2
active
oldest
votes
There seems little point in creating a new post entry for each of your products if your table of products already has all of the information you wish to display.
Your best bet is to create a single page for example "Product" and then setup your own rewrite rule, using add_rewrite_rule, so that you can setup links such as /product/some-product-alias
. You would then need to perform a query on the product alias to lookup the product information from your product table and then display this on the template (either use page-product.php or create a template and assign this in the admin)
There's a little more information on setting up the redirects in this answer of mine.
add a comment
|
You could add a custom template when certain URL patterns are matched and then print on it whatever you want using your own functions to return your database query results dynamically.
The following sample adds a new custom template suggestion. So that always when the URL contains foobar
as first segment and a non-empty second segment the foobar.php
template from your current theme will be rendered.
add_action('template_include', 'template_suggestions');
function template_suggestions($template)
$segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$foobar_template = locate_template(['foobar.php']);
if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar' && $foobar_template !== '')
status_header(200);
return $foobar_template;
return $template;
Now use any other custom function to return your database query results.
function foobar_results()
$myrows = [];
$segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar')
global $wpdb;
$myrows = $wpdb->get_results( "SELECT * FROM mytable WHERE id = $segments[2]" );
return $myrows;
And then in foobar.php
simply loop through the results.
<?php foreach(foobar_results() as $row): ?>
<?php print $row->id; ?>
<?php endforeach; ?>
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "110"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f334410%2fcreate-pages-from-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There seems little point in creating a new post entry for each of your products if your table of products already has all of the information you wish to display.
Your best bet is to create a single page for example "Product" and then setup your own rewrite rule, using add_rewrite_rule, so that you can setup links such as /product/some-product-alias
. You would then need to perform a query on the product alias to lookup the product information from your product table and then display this on the template (either use page-product.php or create a template and assign this in the admin)
There's a little more information on setting up the redirects in this answer of mine.
add a comment
|
There seems little point in creating a new post entry for each of your products if your table of products already has all of the information you wish to display.
Your best bet is to create a single page for example "Product" and then setup your own rewrite rule, using add_rewrite_rule, so that you can setup links such as /product/some-product-alias
. You would then need to perform a query on the product alias to lookup the product information from your product table and then display this on the template (either use page-product.php or create a template and assign this in the admin)
There's a little more information on setting up the redirects in this answer of mine.
add a comment
|
There seems little point in creating a new post entry for each of your products if your table of products already has all of the information you wish to display.
Your best bet is to create a single page for example "Product" and then setup your own rewrite rule, using add_rewrite_rule, so that you can setup links such as /product/some-product-alias
. You would then need to perform a query on the product alias to lookup the product information from your product table and then display this on the template (either use page-product.php or create a template and assign this in the admin)
There's a little more information on setting up the redirects in this answer of mine.
There seems little point in creating a new post entry for each of your products if your table of products already has all of the information you wish to display.
Your best bet is to create a single page for example "Product" and then setup your own rewrite rule, using add_rewrite_rule, so that you can setup links such as /product/some-product-alias
. You would then need to perform a query on the product alias to lookup the product information from your product table and then display this on the template (either use page-product.php or create a template and assign this in the admin)
There's a little more information on setting up the redirects in this answer of mine.
answered Apr 15 at 10:30
Alexander HolsgroveAlexander Holsgrove
1,4561 gold badge9 silver badges17 bronze badges
1,4561 gold badge9 silver badges17 bronze badges
add a comment
|
add a comment
|
You could add a custom template when certain URL patterns are matched and then print on it whatever you want using your own functions to return your database query results dynamically.
The following sample adds a new custom template suggestion. So that always when the URL contains foobar
as first segment and a non-empty second segment the foobar.php
template from your current theme will be rendered.
add_action('template_include', 'template_suggestions');
function template_suggestions($template)
$segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$foobar_template = locate_template(['foobar.php']);
if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar' && $foobar_template !== '')
status_header(200);
return $foobar_template;
return $template;
Now use any other custom function to return your database query results.
function foobar_results()
$myrows = [];
$segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar')
global $wpdb;
$myrows = $wpdb->get_results( "SELECT * FROM mytable WHERE id = $segments[2]" );
return $myrows;
And then in foobar.php
simply loop through the results.
<?php foreach(foobar_results() as $row): ?>
<?php print $row->id; ?>
<?php endforeach; ?>
add a comment
|
You could add a custom template when certain URL patterns are matched and then print on it whatever you want using your own functions to return your database query results dynamically.
The following sample adds a new custom template suggestion. So that always when the URL contains foobar
as first segment and a non-empty second segment the foobar.php
template from your current theme will be rendered.
add_action('template_include', 'template_suggestions');
function template_suggestions($template)
$segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$foobar_template = locate_template(['foobar.php']);
if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar' && $foobar_template !== '')
status_header(200);
return $foobar_template;
return $template;
Now use any other custom function to return your database query results.
function foobar_results()
$myrows = [];
$segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar')
global $wpdb;
$myrows = $wpdb->get_results( "SELECT * FROM mytable WHERE id = $segments[2]" );
return $myrows;
And then in foobar.php
simply loop through the results.
<?php foreach(foobar_results() as $row): ?>
<?php print $row->id; ?>
<?php endforeach; ?>
add a comment
|
You could add a custom template when certain URL patterns are matched and then print on it whatever you want using your own functions to return your database query results dynamically.
The following sample adds a new custom template suggestion. So that always when the URL contains foobar
as first segment and a non-empty second segment the foobar.php
template from your current theme will be rendered.
add_action('template_include', 'template_suggestions');
function template_suggestions($template)
$segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$foobar_template = locate_template(['foobar.php']);
if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar' && $foobar_template !== '')
status_header(200);
return $foobar_template;
return $template;
Now use any other custom function to return your database query results.
function foobar_results()
$myrows = [];
$segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar')
global $wpdb;
$myrows = $wpdb->get_results( "SELECT * FROM mytable WHERE id = $segments[2]" );
return $myrows;
And then in foobar.php
simply loop through the results.
<?php foreach(foobar_results() as $row): ?>
<?php print $row->id; ?>
<?php endforeach; ?>
You could add a custom template when certain URL patterns are matched and then print on it whatever you want using your own functions to return your database query results dynamically.
The following sample adds a new custom template suggestion. So that always when the URL contains foobar
as first segment and a non-empty second segment the foobar.php
template from your current theme will be rendered.
add_action('template_include', 'template_suggestions');
function template_suggestions($template)
$segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$foobar_template = locate_template(['foobar.php']);
if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar' && $foobar_template !== '')
status_header(200);
return $foobar_template;
return $template;
Now use any other custom function to return your database query results.
function foobar_results()
$myrows = [];
$segments = explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
if (isset($segments[1]) && isset($segments[2]) && $segements[1] === 'foobar')
global $wpdb;
$myrows = $wpdb->get_results( "SELECT * FROM mytable WHERE id = $segments[2]" );
return $myrows;
And then in foobar.php
simply loop through the results.
<?php foreach(foobar_results() as $row): ?>
<?php print $row->id; ?>
<?php endforeach; ?>
answered Apr 15 at 11:11
leymannxleymannx
1,6512 gold badges16 silver badges27 bronze badges
1,6512 gold badges16 silver badges27 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to WordPress Development Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fwordpress.stackexchange.com%2fquestions%2f334410%2fcreate-pages-from-database%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown