include_once ("wp-blog-header.php"); // la ruta donde esté este fichero en nuestro wp
header('Content-Type: text/html; charset=iso-8859-1');
getPostsDelWp();
En el fichero functions.php dentro de la carpeta del tema de nuestro wp añadir al final:
function getPostsDelWp(){
//default values obj from post.php.
//pass these in as args that you really want
$args = array(
'numberposts' => 6
);
$post_array = get_posts($args); //as found in wp-includes/post.php
for($i=0; $i<count($post_array); $i++){
// print_r($post_array);
$post_title = utf8_decode($post_array[$i]->post_title);
$post_name = $post_array[$i]->post_name;
$post_permalink = $post_name;
$url = "";
if(has_post_thumbnail($post_array[$i]->ID)):
$thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id($post_array[$i]->ID), 'medium');
$url = $thumbnail[0];
endif;
echo "<h1>".$post_title."</h1>";
echo "<img src='".$url."'>";
echo "<h3>".$post_array[$i]->post_content."</h3>";
echo "<h3><a href='".$post_permalink."' target=_blank>Ver más</a></h3>";
$argsComment = array(
'author_email' => '',
'author__in' => '',
'author__not_in' => '',
'include_unapproved' => '',
'fields' => '',
'ID' => '',
'comment__in' => '',
'comment__not_in' => '',
'karma' => '',
'number' => '',
'offset' => '',
'orderby' => '',
'order' => 'DESC',
'parent' => '',
'post_author__in' => '',
'post_author__not_in' => '',
'post_ID' => '', // ignored (use post_id instead)
'post_id' => $post_array[$i]->ID,
'post__in' => '',
'post__not_in' => '',
'post_author' => '',
'post_name' => '',
'post_parent' => '',
'post_status' => '',
'post_type' => '',
'status' => 'all',
'type' => '',
'type__in' => '',
'type__not_in' => '',
'user_id' => '',
'search' => '',
'count' => false,
'meta_key' => '',
'meta_value' => '',
'meta_query' => '',
'date_query' => null, // See WP_Date_Query
);
$arrComment = get_comments( $argsComment);
echo "<h2>COMENTARIOS</h2>";
foreach($arrComment as $clave=>$valor) {
echo "<b>".$valor->comment_date."<br>";
echo $valor->comment_author_email." comentó:</b> ".utf8_decode($valor->comment_content)."<br>";
}
echo "<hr>";
}
}
Mostrar en una web externa contenidos de wordpress filtrando por parámetros:
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
$_GET["numberposts"] = 15;
$num = $_GET["numberposts"] ?: '10'; // si no existe numberPosts saca 10
$id_cat = 22;
$postID = 0; // $_GET["postid"];
$type = "catFeed";
switch ($type){
case "singlePost":
$posts = get_posts('p='.$postID.'&numberposts=1');
break;
case "catFeed":
$posts = get_posts('category='.$id_cat.'&numberposts='.$num.'&order=ASC');
break;
default:
$posts = get_posts('numberposts='.$num.'&order=ASC');
}
if($type == "catFeed") {
echo "<h1>".get_cat_name($id_cat)."</h1>";
echo "<h2>".category_description($id_cat)."</h2>";
}
foreach ($posts as $post) : start_wp();
echo the_id()."<br>";
echo the_title()."<br>";
echo the_permalink_rss()."<br>";
echo the_author()."<br>";
echo the_date()."<br>";
echo the_excerpt()."<br>";
if($type == "singlePost"){
echo the_content();
}
echo "<hr>";
endforeach;
No hay comentarios:
Publicar un comentario