MULTIMEDIA, Video digital, Grabación, Diseño gráfico, Diseño web, Programación > Webmasters - Diseño Web - Programación - Diseño gráfico

Ruta de enlace o variable que me devuelva el último post en Wordpress

(1/2) > >>

_aLinG_:
Pues eso. Me gustaría poder poner un enlace que apunte siempre al último post. ¿Se puede hacer con código HTML? Puedo editar el código HTML antes y después de la imagen de portada sin problemas.

Un saludo.

Liamngls:
La única cosa que se me ocurre es que utilices algún plugin para mostrar feeds y agregues el tuyo propio condicionándolo a que solo muestre una entrada, en la sidebar del blog de dabo puedes ver como funciona el suyo y como quedaría:

http://www.daboblog.com/

No es una solución muy elegante, pero funcionaría :)

_aLinG_:
He encontrado por ahí un plugin que genera una salida con una lista de los últimos post publicados. Estoy leyendome el código, a ver que puedo sacar.

El problema es que el plugin me devuelve un texto con un título y un link, y estoy viendo como poder extraer sólo el link. Complicado no habiendo programado en php pero a ver qué saco  :???: :???:

Si sabéis como hacerlo más o menos rápido, coartando los resultados de salida del plugin y dejándolos sólo en una simple URL no me vendría mal. De todas formas intentaré sacarlo yo.

Gracias por le apunte  :) :)

_aLinG_:
Creo qque la madre del cordero está en este trozo del plugin:


--- Código: ---/* Check for how to display the most recent post */

if (($post_display == 0) || ($post_display == 1)) {
            /* Return the title and content/excerpt */
            $return_recent_post = $title_begin . "<b>";
            if ($link_to_post == 1) {
                /* Link the title to the post's permalink */
                $return_recent_post = $return_recent_post . "<a href=\"" . get_permalink($single_post_id) . "\" ";
                $return_recent_post = $return_recent_post . "alt = \" Permanent Link to " . $single_post_title . "\">";
                $return_recent_post = $return_recent_post . $single_post_title . "</a></b>" . $title_end . $single_post;
            }
            else if ($link_to_post == 2) {
                /* Link the title to the alternate link */
                $return_recent_post = $return_recent_post . "<a href=\"" . $alt_link;
                $return_recent_post = $return_recent_post . "\">";
                $return_recent_post = $return_recent_post . $single_post_title . "</a></b>" . $title_end . $single_post;
            }
            else {
                /* Do not link the title to anything */
                $return_recent_post = $return_recent_post . $single_post_title . "</b>" . $title_end . $single_post;
            }
        }
        else if ($post_display == 2) {
            /* Return only the title */
            $return_recent_post = $title_begin . "<b>";
            if ($link_to_post == 1) {
                /* Link the title to the post's permalink */
                $return_recent_post = $return_recent_post . "<a href=\"" . get_permalink($single_post_id) . "\" ";
                $return_recent_post = $return_recent_post . "alt = \" Permanent Link to " . $single_post_title . "\">";
                $return_recent_post = $return_recent_post . $single_post_title . "</a></b>" . $title_only_end;
            }
            else if ($link_to_post ==2) {
            /* Link the title to the alternate link */
            $return_recent_post = $return_recent_post . "<a href=\"" . $alt_link;
                $return_recent_post = $return_recent_post . "\">";
                $return_recent_post = $return_recent_post . $single_post_title . "</a></b>" . $title_only_end;
            }
            else {
                /* Do not link the title to anything */
                $return_recent_post = $return_recent_post . $single_post_title . "</b>" . $title_only_end;
            }
        }
        else if (($post_display == 3) || ($post_display == 4)) {
            /* Return only the content/excerpt */
            $return_recent_post = $single_post;
        }

/* Return the most recent post! */
/* Use the wpautop function to pad with <p> tags where needed */
if ($paragraph_pad == 1) {
  $return_recent_post = wpautop($return_recent_post);
        }
       
return $return_recent_post;
}
}

?>
--- Fin del código ---

...concretamente aquí:


--- Código: --- if ($link_to_post == 1) {
                /* Link the title to the post's permalink */
                $return_recent_post = $return_recent_post . "<a href=\"" . get_permalink($single_post_id) . "\" ";
                $return_recent_post = $return_recent_post . "alt = \" Permanent Link to " . $single_post_title . "\">";
                $return_recent_post = $return_recent_post . $single_post_title . "</a></b>" . $title_end . $single_post;
--- Fin del código ---

Que hace referencia a lo que ocurre si seteas esa opción del plugin con el valor 1. Eso enlaza el título del post a su correspondiente link. Lo que necesito ahora es extraer ese link para poderlo usar en la imagen de fondo de la portada y en el link a la galería  :???: :???:

_aLinG_:
Más averiguaciones. La ID del post reciente la lee de aquí:


--- Código: ---/* If there is a post category specified, continue... */
if ($post_category_id) {

if (($post_display == 1) || ($post_display == 4)) {
/* Query the title and excerpt */
$req_post = "SELECT wp_posts.ID, wp_posts.post_title, wp_posts.post_excerpt FROM wp_posts, wp_term_taxonomy, wp_term_relationships WHERE (wp_term_taxonomy.term_id = $post_category_id) AND (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) AND (wp_term_relationships.object_id = wp_posts.ID) AND (wp_posts.post_modified <= '$now') AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.ID DESC LIMIT 1;";

$posts = $wpdb->get_results($req_post);

foreach ($posts as $post) {
$single_post_id = $post->ID;
$single_post_title = $post->post_title;
$single_post = $post->post_excerpt;
}
}
else if (($post_display == 0) || ($post_display == 2) || ($post_display == 3)) {
            /* Query the title and content */
$req_post = "SELECT wp_posts.ID, wp_posts.post_title, wp_posts.post_content FROM wp_posts, wp_term_taxonomy, wp_term_relationships WHERE (wp_term_taxonomy.term_id = $post_category_id) AND (wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id) AND (wp_term_relationships.object_id = wp_posts.ID) AND (wp_posts.post_modified <= '$now') AND (wp_posts.post_status = 'publish') ORDER BY wp_posts.ID DESC LIMIT 1;";

$posts = $wpdb->get_results($req_post);

foreach ($posts as $post) {
$single_post_id = $post->ID;
$single_post_title = $post->post_title;
$single_post = $post->post_content;
}
}

--- Fin del código ---

Lo demás es código para que el código de números que hace funcionar al plugin y gestionar als otras opciones funcione...a ver si logro recomponer algo con estos trozos y la estructura general...:S

Navegación

[0] Índice de Mensajes

[#] Página Siguiente

Ir a la versión completa