include_once ("wp-blog-header.php");
header('Content-Type: text/html; charset=iso-8859-1');
$response = wp_remote_get('http://www.otroservidor.com/wp-json/wp/v2/posts/');
$posts = json_decode(wp_remote_retrieve_body( $response ));
print_r($posts);
Mostrando entradas con la etiqueta Wordpress: external web. Mostrar todas las entradas
Mostrando entradas con la etiqueta Wordpress: external web. Mostrar todas las entradas
Wordpress: Obtener los post de un servidor remoto externo
Desde una página externa de tu wordpress:
Wordpress: Insertar un comentario desde una web externa
$agent = $_SERVER['HTTP_USER_AGENT'];
$arr = array(
'comment_post_ID' => 10, // id del post
'comment_author' => 'Pepe',
'comment_author_email' => 'pepe@gmail.com',
'comment_author_url' => 'http://www.pepe.com',
'comment_content' => utf8_encode('En otro país multicolor nació una abeja bajo el sol'),
'comment_author_IP' => '127.3.1.1',
'comment_agent' => $agent,
'comment_date' => date('Y-m-d H:i:s'),
'comment_date_gmt' => date('Y-m-d H:i:s'),
'comment_approved' => 1,
);
$id_coment = wp_insert_comment($arr);
if (is_wp_error($return)) {
die($id_coment->get_error_message());
}
else {
echo "Se inserto correctamente el comentario con el id: {$id_coment}";
}
Wordpress: insertar un nuevo usuario desde una web externa
En tu web externa:
include_once ("wp-blog-header.php");
header('Content-Type: text/html; charset=iso-8859-1');
$arr = array(
"user_pass" => "1234",
"user_login" => "carlossierra",
"user_nicename" => "carlossierra",
"user_email" => "carlossierra@example.com",
"display_name" => "Carlos Sierra",
"first_name" => "Carlos",
"last_name" => "Sierra",
);
insertNewUser($arr);
En el functions.php del tema activo:
function insertNewUser($arr) {
if(email_exists($arr["user_email"]))
die("<br>Error: Ese email ya existe");
if (username_exists($arr["user_login"]))
die("<br>Error: Ese username ya existe");
$insert_user_result = wp_insert_user($arr);
if (is_wp_error($return)) {
die($insert_user_result->get_error_message());
}
else {
echo "Se inserto correctamente con el id: {$insert_user_result}";
}
}
Wordpress: Obtener los datos del usuario logueado desde una web externa
En tu página externa:
En el fuctions.php del tema:
include_once ("wp-blog-header.php");
header('Content-Type: text/html; charset=iso-8859-1');
getUserLogueado();
En el fuctions.php del tema:
function getUserLogueado() {
if (is_user_logged_in()) {
global $current_user;
get_currentuserinfo();
echo 'Hola ' . $current_user->display_name;
echo "<br>Tus datos son:";
print_r($current_user);
}
else {
echo '<a href="'. get_bloginfo('url') .'/wp-admin" class="loginlinktop">Loguearte</a>';
}
}
Wordpress: Mostrar el excerpt (fragmento) del contenido de la entrada
En el functions.php:
function get_post_excerpt_by_id( $post_id ) {
global $post;
$post = get_post( $post_id );
setup_postdata( $post );
$the_excerpt = get_the_excerpt();
wp_reset_postdata();
return $the_excerpt;
}
for($i=0; $i<count($post_array); $i++){
...
echo get_post_excerpt_by_id($post_array[$i]->ID);
}
Wordpress: Mostrar en una web externa el contenido y comentarios de las entradas de un WP
En el php de nuestra web:
En el fichero functions.php dentro de la carpeta del tema de nuestro wp añadir al final:
Mostrar en una web externa contenidos de wordpress filtrando por parámetros:
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;
Suscribirse a:
Entradas (Atom)
