你可以使用phpmyadmin将wordpress帖子放到外部网站吗?

时间:2016-10-26 19:27:18

标签: php mysql wordpress phpmyadmin

我知道这可能是一个愚蠢的问题。我有一个用PHP构建的网站,我有一个部分,我想从Wordpress中提取3个响应式帖子。

我尝试过使用API​​和JSON卷发而没有运气,主要是因为我对这些事情缺乏了解。不知道是否可以更容易地进入PHPMyAdmin然后我可以编码从中提取信息并使其响应?

2 个答案:

答案 0 :(得分:1)

如果我这样做,我会装配我的WordPress网站发布您尝试呈现的文章的RSS源,并使用一些JavaScript在您自定义的PHP网站上显示该源。

可以使用WordPress插件和JavaScript组件来完成所有这些工作。

答案 1 :(得分:0)

所以这是我修改过的php

<section id="blog">
<div class="container-fluid">
    <div class="row">
<div id="featured_posts">

<?php

// output RSS feed to HTML
output_rss_feed('http://www.bmcsquincy.com/featured_posts/feed', 20, true, true, 200);

// Check http://www.systutorials.com/136102/a-php-function-for-fetching-rss-feed-and-outputing-feed-items-as-html/ for description
// RSS to HTML
/*
    $item_cnt: max number of feed items to be displayed
    $max_words: max number of words (not real words, HTML words)
    if <= 0: no limitation, if > 0 display at most $max_words words
 */
function get_rss_feed_as_html($feed_url, $max_item_cnt = 10, $show_date = true, $show_description = true, $max_words = 0, $cache_timeout = 7200, $cache_prefix = "/tmp/rss2html-")
{
    $result = "";
    // get feeds and parse items
    $rss = new DOMDocument();
    $cache_file = $cache_prefix . md5($feed_url);
    // load from file or load content
    if ($cache_timeout > 0 &&
        is_file($cache_file) &&
        (filemtime($cache_file) + $cache_timeout > time())) {
            $rss->load($cache_file);
    } else {
        $rss->load($feed_url);
        if ($cache_timeout > 0) {
            $rss->save($cache_file);
        }
    }
    $feed = array();
    foreach ($rss->getElementsByTagName('item') as $node) {
        $item = array (
            'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
            'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
            'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
            'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
        );
        $content = $node->getElementsByTagName('encoded'); // <content:encoded>
        if ($content->length > 0) {
            $item['content'] = $content->item(0)->nodeValue;
        }
        array_push($feed, $item);
    }
    // real good count
    if ($max_item_cnt > count($feed)) {
        $max_item_cnt = count($feed);
    }
    $result .= '<ul class="feed-lists">';


    //ADDED THIS FOR POST AMOUNT
    $max_item_cnt = 3;

    for ($x=0;$x<$max_item_cnt;$x++) {
        $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
        $link = $feed[$x]['link'];
        $result .= '<li class="feed-item">';
        $result .= '<div class="feed-title"><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong></div>';
        if ($show_date) {
            $date = date('l F d, Y', strtotime($feed[$x]['date']));
            $result .= '<small class="feed-date"><em>Posted on '.$date.'</em></small>';
        }
        if ($show_description) {
            $description = $feed[$x]['desc'];
            $content = $feed[$x]['content'];
            // find the img
            $has_image = preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $content, $image);
            // no html tags
            $description = strip_tags($description, '');
            // whether cut by number of words
            if ($max_words > 0) {
                $arr = explode(' ', $description);
                if ($max_words < count($arr)) {
                    $description = '';
                    $w_cnt = 0;
                    foreach($arr as $w) {
                        $description .= $w . ' ';
                        $w_cnt = $w_cnt + 1;
                        if ($w_cnt == $max_words) {
                            break;
                        }
                    }
                    $description .= " ...";
                }
            }
            // add img if it exists



                //ADDED THE P IN DESCRIPTION LINE TO FOR A BREAK BY IMAGE

                if ($has_image == 1) {
                    $description = '<p> <img class="feed-item-image" src="' . $image['src'] . '" /></p>' . $description;
                }
                $result .= '<div class="feed-description">' . $description;

                //ADDED THE P IN THIS TO LINE BREAK CONTINUE READING

                $result .= '<p> <a href="'.$link.'" title="'.$title.'">Continue Reading &raquo;</a></p>'.'</div>';
            }
            $result .= '</li>';
        }
        $result .= '</ul>';
        return $result;
    }
    function output_rss_feed($feed_url, $max_item_cnt = 10, $show_date = true, $show_description = true, $max_words = 0)
    {
        echo get_rss_feed_as_html($feed_url, $max_item_cnt, $show_date, $show_description, $max_words);
    }
    ?>

    </div><!--END FEATURED POSTS-->
        </div><!--END ROW-->
        </div><!--END CONTAINER-->
    </section><!--END SECTION BLOG-->       

这是我的css

#blog {
    background-color: yellow;
    color: #dbdbdb;
    width: 100%;
    padding-top: 100px;
    padding-bottom: 100px;
    margin: 0px auto 0px auto;
}

#featured_posts {
    background-color: pink;
    max-width: 1200px;
    margin: 0px auto 0px auto;
    padding: 5px;
}

#featured_posts ul {
    display: inline-block;
    margin: 0px auto 0px auto;
    text-align: center;
    padding: 0px;
}

#featured_posts li {
    list-style-type: none;
    text-align: left;
    padding: 30px;
    float: left;
    font-family: pathwaygothic;
    font-size: 1em;
    background-color: purple;
    max-width: 1200px;
    margin-left: 25px;
}

.feed-lists {
  background-color: aqua;
  width: 100%;

}

.feed-title a {
    color: red;
}

.feed-date {
    color: aqua;
}

.feed-description {
    width: 300px;
}

.feed-lists li {
    background-color: green;
}