Can WordPress post content be external data (not from the database)

懵懂的女人 提交于 2019-12-23 02:53:31

问题


I am trying to display a page based on some data returned from an external API (Amazon). This data is formatted then, has to be displayed on a page, created on the fly, based on URL querys. I can already do this with shortcodes but this has to be from the query.

I see all kinds of info in the codex on returning custom query_posts into the loop from the database. However, I cannot find info getting external data to appear on a page.

Is this possible in WordPress? (anything is possible, right?) Just point me to some functions, filters or tutorials please.


回答1:


If I understand you correctly, you want to retrieve data dynamically and display it in a WordPress page?

There are many ways to do this, but here's one option:

  1. Create a Page Template
  2. Create a WordPress page and use the Page Template created in step 1.
  3. Edit the Page Template to call the external API and display the data

I'm guessing you've been trying to find a way to do this from the "content" of a page or post, but the easiest way is to put the code in a custom Page Template.

UPDATE: If you want to programmatically create a page, this might work for you: http://wordpress.org/support/topic/how-to-create-pages-programmatically?replies=5#post-1230619




回答2:


http://www.prelovac.com/vladimir/wordpress-shortcode-snippet-to-display-external-files

This is a snippet to display external data in a post.

Would this help? If the dynamic page was a HTML page and THEM displayed in WP.




回答3:


Yep, Thats possible.

I Did by using bridges.

You can do it by add "add_meta_boxes" action.

Inside the meta box function you can add call and get the external page contents, or can give your own forms .etc

My Code :

/*
 * Add Meta Product Type Field to POST
 */

 add_action('add_meta_boxes', 'meta_box_product_type_add');

My Meta Box

/*
 * Product Type Meta Box Init
 */

 function meta_box_product_type_add()
 {
   add_meta_box('ptype_testing', 'Product Type', 'add_ptype', 'testing', 'normal', 'high');
 }

/*
 * Product Type Field
 */

 function add_ptype()
  { ?>
   <label>Type of Product : </label>
   <select name="ptype" id="ptypes">
    <option>----Select----</option>
    <option>Physical</option>
    <option>Virtual</option>
   </select>
   <label>Unit :</label>
   <select name="punit" id="units">
    <option>----Select----</option>
    <option>KG</option>
    <option>Mtr</option>
    <option>Ltr</option>
   </select>
   <?php
  }

Try It....



来源:https://stackoverflow.com/questions/4937948/can-wordpress-post-content-be-external-data-not-from-the-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!