-
AuthorPosts
-
May 29, 2020 at 8:11 pm #1217848
I am trying to display some images and content or excerpt from the posts outside wordpress using PHP. Can you please share an example of how can I do it?
The idea is a simple page that displays exactly featured full images by ID.
Query the database or using require “wp-load.php”;.
Show full featured image from post 3
Show text from post 3Show full featured image from post 8
Show full featured image from post 14
Show text from post 14And so on.
So with PHP how can I do it?
I understand this is not completely enfold related, but maybe someone wants to help :)
Thanks.
June 9, 2020 at 1:40 pm #1220842Hey peterolle,
Thank you for the inquiry.
Have you tried using the WordPress REST API? You should be able to fetch posts or any available data from your WordPress installation to any platform using HTTP requests.
// https://developer.wordpress.org/rest-api/reference/
Best regards,
IsmaelJune 9, 2020 at 1:42 pm #1220843Thank you Ismael, yes, but I am not being able to do it per ID.
Show here just featured image from post 8, here text from post 34, etc…
June 9, 2020 at 3:11 pm #1220884Hi,
Please try adding following code to bottom of functions.php file
function av_get_thumb_excerpt( $atts ) { $a = shortcode_atts( array( 'id' => '', ), $atts ); $output = get_the_excerpt($a['id']); $output .= get_the_post_thumbnail($a['id']); return $output; } add_shortcode( 'my_shortcode', 'av_get_thumb_excerpt' );
Then you can use the shortcode as following
[my_shortcode id="10"]
and replace ID (10) depending on which post you would like to display. I attached the result in private content field :)
Regards,
YigitJune 9, 2020 at 5:17 pm #1220907Thank you Yigit.
The problem here is that I need to display featured image and text outside WordPress. In a stand alone PHP file.
June 9, 2020 at 8:38 pm #1220960Hi,
Sorry I thought outside of the loop.
Thank you Ismael, yes, but I am not being able to do it per ID.
Show here just featured image from post 8, here text from post 34, etc…
So back to that, you can use post ID’s as with wp/v2/posts/8?_embed and wp/v2/posts/34?_embed
Best regards,
Yigit -
AuthorPosts
- You must be logged in to reply to this topic.