Digital_Jedi_3 Digital_Jedi_3 - 1 month ago 8
MySQL Question

Can you use phpmyadmin to put wordpress posts to an external site?

I know it may be a stupid question. I have a website that I have built in PHP and I have a section that I would like 3 responsive posts to pull in from Wordpress.

I have tried using API and JSON curls and not having any luck, mostly because I lack knowledge on those things. Didn't know if it could be easier to pull into PHPMyAdmin then I could code to pull in the info from that and make it responsive?

Answer

So here is my revised 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-->       

Here is my 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;
}