Php Wordpress-使用Wordpress之外的函数
我正在使用以下代码从另一个页面访问我的wordpress:Php Wordpress-使用Wordpress之外的函数,php,wordpress,Php,Wordpress,我正在使用以下代码从另一个页面访问我的wordpress: <?php include $_SERVER['DOCUMENT_ROOT'].'/wp-load.php'; global $wpdb; $image_ID = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_value = '6036' AND meta_key = '_wp_attached_file
<?php
include $_SERVER['DOCUMENT_ROOT'].'/wp-load.php';
global $wpdb;
$image_ID = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_value = '6036' AND meta_key = '_wp_attached_file'");
//regenerate thumbnail
$fullsizepath = get_attached_file( $image_ID );
$metadata = wp_generate_attachment_metadata( $image_ID, $fullsizepath );
wp_update_attachment_metadata( $image_ID, $metadata );
?>
$wpdb查询工作正常,也可以获取附加的文件。唯一的问题是我不能使用
有人知道为什么会这样吗?我忘了写点什么了吗
编辑:我刚刚意识到我忘记了
include(ABSPATH.'wp admin/includes/image.php')代码>您需要包含wp-blog-header.php来设置wordpress环境
<?php
require('blog/wp-blog-header.php');
$args = array( 'numberposts' => 5, 'post_status'=>"publish", 'post_type'=>"post", 'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<ul class="headline">
<li class="title">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
</ul>
<?php endforeach; ?>
-
<?php
require('blog/wp-blog-header.php');
$args = array( 'numberposts' => 5, 'post_status'=>"publish", 'post_type'=>"post", 'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<ul class="headline">
<li class="title">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
</ul>
<?php endforeach; ?>