首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在我的外部代码中显示来自wordpress数据库的特征图像

在我的外部代码中显示来自wordpress数据库的特征图像
EN

Stack Overflow用户
提问于 2016-10-11 18:05:29
回答 1查看 23关注 0票数 0

我有这个代码,我需要显示从数据库的Wordpress帖子图像。有没有人能帮我?现在它只显示来自特定作者的帖子的标题和内容。但我需要显示post图像...

谢谢

代码语言:javascript
复制
$db_username = '***';
$db_password = '***';
$db_database = '***';  

$blog_url = 'myBlogSiteUrl.com/'; //base folder for the blog. Make SURE there is a slash at the end  

//connect to the database
$con = mysql_connect('***', $db_username, $db_password);
@mysql_select_db($db_database) or die("Unable to select database");
$query = "
        Select * 
        FROM wp_posts
        WHERE post_type='advert' 
        AND post_author='16' 
        AND post_status='publish' 
        ORDER BY id DESC LIMIT 2
    ";

$query_result = mysql_query($query);  

while ($row = mysql_fetch_array($query_result)) {

    $content = $row['post_content'];

    echo ('
        <div class="blog_cont">
        <strong>'.$row['post_title'].'</strong>
        <br>
        <span>'.$content.'</span>
        <br>
        <a href="'.$row['guid'].'" target="_blank">More >></a>
        ');
}
@mysql_close($con);
EN

回答 1

Stack Overflow用户

发布于 2016-10-11 18:41:07

看起来你正在进行ajax调用,让wordpress为你处理,然后显示图片或任何存储在db中的东西将会容易得多。

https://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action)

如果没有,您仍然可以处理Wordpress请求。在你的插件或模板中,wordpress处理GET请求,你仍然可以使用functions.php函数。

例如:

代码语言:javascript
复制
<?php

isset($_GET['your_custom_get_variable']){

    echo esc_url( home_url( '/' ) );

    exit(); // don't let wordpress output anything else

}

但是,如果只进行AJAX调用,则第一个方法要干净得多

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39974891

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档