Voglio ottenere "abc_15_11_02_3" da http://example.com/project_name/abc_15_11_02_3/. Come posso fare questo?Come ottenere post lumaca da post in wordpress?
12
A
risposta
1
È possibile recuperare dall'oggetto posta in questo modo:
global $post;
$post->post_name;
10
Se si desidera ottenere slug del post dal loop quindi utilizzare:
global $post;
echo $post->post_name;
Se si vuole ottenere slug del post fuori dal ciclo quindi utilizzare:
$post_id = 45; //specify post id here
$post = get_post($post_id);
$slug = $post->post_name;
4
È possibile fare questo è per molti versi come:
1- È possibile utilizzare Wordpress variabile globale $post
:
<?php
global $post;
$post_slug=$post->post_name;
?>
2- Oppure si può ottenere l'uso:
$slug = get_post_field('post_name', get_post());
3- Oppure ottieni l'url completo e quindi utilizza la funzione PHP parse_url
:
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url_path = parse_url($url, PHP_URL_PATH);
$slug = pathinfo($url_path, PATHINFO_BASENAME);
Spero che i metodi ti aiuteranno.
20
È possibile ottenere che utilizzando i seguenti metodi:
<?php $post_slug = get_post_field('post_name', get_post()); ?>
oppure è possibile utilizzare questo codice facile:
<?php
global $post;
$post_slug = $post->post_name;
?>
2
Wordpress: Get Articolo/Pagina slug
<?php
// Custom function to return the post slug
function the_slug($echo=true){
$slug = basename(get_permalink());
do_action('before_slug', $slug);
$slug = apply_filters('slug_filter', $slug);
if($echo) echo $slug;
do_action('after_slug', $slug);
return $slug;
}
?>
<?php if (function_exists('the_slug')) { the_slug(); } ?>
Problemi correlati
- 1. Wordpress interrogazione singolo post da lumaca
- 2. Ottieni WordPress Post ID dal titolo post
- 3. Ottenere l'ID messaggio WordPress del post corrente
- 4. Wordpress: tentativo di ottenere post per tag
- 5. Wordpress ottiene più post da id
- 6. Wordpress strip single shortcode da post
- 7. Wordpress tipo personalizzato impaginazione post
- 8. Integrare Wordpress Post con Cakephp3
- 9. Come escludere i post protetti da password nel ciclo WordPress
- 10. Come ottenere i parametri da AFNETWORKING POST
- 11. Pubblica post Wordpress in Google Plus?
- 12. come faccio a ottenere solo 1 post da ogni categoria in wordpress
- 13. Ottieni tutti gli ID di post in Wordpress
- 14. Mostra l'immagine allegata al post su Wordpress
- 15. Wordpress Permalink personalizzato per post semplici
- 16. Categorie di tipi di post personalizzati Wordpress
- 17. come ottenere i valori POST in perl
- 18. Wordpress: ottieni informazioni sull'autore dall'ID post
- 19. Come condividere i miei post wordpress in instagram
- 20. Come si formatta la data del post in Wordpress?
- 21. Wordpress Loop: come avvolgere ogni 3 post in un div?
- 22. Ottenere una variabile POST
- 23. Come ottenere un payload da un POST in Play 2.0
- 24. Come ottenere i dati in Struts da AngularJS post
- 25. Ottieni tutti i post dalla tassonomia personalizzata in Wordpress
- 26. Come posso ottenere i post dalla categoria usando lo slug?
- 27. come ottenere js POST in asp.net webform?
- 28. Come ottenere il titolo della categoria in un post in Wordpress?
- 29. Consenti agli utenti di ordinare i post in Wordpress
- 30. Dividi automaticamente il contenuto del post WordPress in 3 colonne?