4

페이스 북의 좋아하는 활동, 활동 등을 기반으로 특정 사용자의 콘텐츠를 생성하는 블로그 페이지를 만들고 싶습니다. 예를 들어 Facebook의 Shakira와 Coca Cola를 좋아합니다. 블로그에 들어가서 Facebook을 통해 연결하면 블로그는 그 정보를 얻고 YouTube API를 통해 Shakira의 YouTube 비디오를 검색하고 WordPress 게시물에 비디오를 표시합니다. 블로그가 코카콜라와 관련된 뉴스를 검색하고 소식에 대한 소식을 게시물에 표시 한 후Wordpress 게시물을 동적으로 렌더링 할 수 있습니까?

FB 연결, YouTube 검색 또는 Google 검색에는 문제가 없습니다. 내 문제는 WordPress입니다. 많은 사용자가있을 수 있고 각 사용자마다 많은 콘텐츠를 생성 할 수 있기 때문에 MySQL 테이블의 모든 게시물을 저장할 수 없습니다. 나는 동적으로 게시물을 생성하고 싶다. 나는 여기서 코드를 요구하지 않고, 어떻게하면 좋은 해결책과 아이디어를 듣고 싶을 뿐이다.

+0

당신은 어떤 방법으로 작업이 솔루션을 가지고 있나요? 지금까지 뭐 해봤 어? – ajtrichards

답변

3

해결책으로 404 페이지를 사용하여이 동적 게시물을 생성 할 수 있습니다.

유사한 솔루션을 제공 여기에 블로그 게시물이있다 : http://www.blogseye.com/creating-fake-wordpress-posts-on-the-fly/

가짜 게시물 생성하는 데 사용되는 코드 :

function kpg_f_content() { 
    global $wp_query; 
    if($wp_query->is_404) { 
     $id=-42; // need an id 
     $post = new stdClass(); 
      $post->ID= $id; 
      $post->post_category= array('uncategorized'); //Add some categories. an array()??? 
      $post->post_content='hey here we are a real post'; //The full text of the post. 
      $post->post_excerpt= 'hey here we are a real post'; //For all your post excerpt needs. 
      $post->post_status='publish'; //Set the status of the new post. 
      $post->post_title= 'Fake Title'; //The title of your post. 
      $post->post_type='post'; //Sometimes you might want to post a page. 
     $wp_query->queried_object=$post; 
     $wp_query->post=$post; 
     $wp_query->found_posts = 1; 
     $wp_query->post_count = 1; 
     $wp_query->max_num_pages = 1; 
     $wp_query->is_single = 1; 
     $wp_query->is_404 = false; 
     $wp_query->is_posts_page = 1; 
     $wp_query->posts = array($post); 
     $wp_query->page=false; 
     $wp_query->is_post=true; 
     $wp_query->page=false; 
    } 
} 

add_action('wp', 'kpg_f_content'); 

이 플러그인에이를 확인하거나 functions.php 파일에 추가를 .

+1

감사합니다. 훌륭한 솔루션입니다. –

0

대체 솔루션 :

add_filter('init', 'custom_function'); 
function custom_function(){ 
    if(is_admin()==true) return false; 

    //check URL 
    if($_SERVER['REQUEST_URI'] != '/hello/') return false; 

    echo 'Hello.'; 
    exit(); 
    } 
0

이 게시물을 만들 수있는 또 다른 방법 동적

$post = array(
    'ID'    => [ <post id> ] // Are you updating an existing post? 
    'post_content' => [ <string> ] // The full text of the post. 
    'post_name'  => [ <string> ] // The name (slug) for your post 
    'post_title'  => [ <string> ] // The title of your post. 
    'post_status' => [ 'draft' | 'publish' | 'pending'| 'future' | 'private' | custom registered status ] // Default 'draft'. 
    'post_type'  => [ 'post' | 'page' | 'link' | 'nav_menu_item' | custom post type ] // Default 'post'. 
    'post_author' => [ <user ID> ] // The user ID number of the author. Default is the current user ID. 
    'ping_status' => [ 'closed' | 'open' ] // Pingbacks or trackbacks allowed. Default is the option 'default_ping_status'. 
    'post_parent' => [ <post ID> ] // Sets the parent of the new post, if any. Default 0. 
    'menu_order'  => [ <order> ] // If new post is a page, sets the order in which it should appear in supported menus. Default 0. 
    'to_ping'  => // Space or carriage return-separated list of URLs to ping. Default empty string. 
    'pinged'   => // Space or carriage return-separated list of URLs that have been pinged. Default empty string. 
    'post_password' => [ <string> ] // Password for post, if any. Default empty string. 
    'guid'   => // Skip this and let Wordpress handle it, usually. 
    'post_content_filtered' => // Skip this and let Wordpress handle it, usually. 
    'post_excerpt' => [ <string> ] // For all your post excerpt needs. 
    'post_date'  => [ Y-m-d H:i:s ] // The time post was made. 
    'post_date_gmt' => [ Y-m-d H:i:s ] // The time post was made, in GMT. 
    'comment_status' => [ 'closed' | 'open' ] // Default is the option 'default_comment_status', or 'closed'. 
    'post_category' => [ array(<category id>, ...) ] // Default empty. 
    'tags_input'  => [ '<tag>, <tag>, ...' | array ] // Default empty. 
    'tax_input'  => [ array(<taxonomy> => <array | string>) ] // For custom taxonomies. Default empty. 
    'page_template' => [ <string> ] // Requires name of template file, eg template.php. Default empty. 
); 
    $post_id = wp_insert_post($post); 

나를 alot을하는 데 도움이 있습니다!. 자세한 내용은

wp_insert_postclickhere

관련 문제