最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - How do I get information about a page, such as featured image, except, and title?

programmeradmin0浏览0评论

Assuming that I learn how to do this, how do I pull information about the user's selected page and display them?

Obviously, I start with

$mytheme_f_page[1] = get_theme_mod( 'mytheme_featured_page_1', '' );

What do I do to pull the information about this page? As there will be three, can I get all three at once or do I need to do it one at a time?

I'm going to need the thumbnail, the title, and the excerpt.

Assuming that I learn how to do this, how do I pull information about the user's selected page and display them?

Obviously, I start with

$mytheme_f_page[1] = get_theme_mod( 'mytheme_featured_page_1', '' );

What do I do to pull the information about this page? As there will be three, can I get all three at once or do I need to do it one at a time?

I'm going to need the thumbnail, the title, and the excerpt.

Share Improve this question asked Jul 1, 2019 at 1:36 Matthew Brown aka Lord MattMatthew Brown aka Lord Matt 1,0683 gold badges13 silver badges34 bronze badges 1
  • 2 You could store the page ID and use functions like get_the_title() and get_the_excerpt(). You could also store an array of page IDs and loop over the array to get the post data. – Sally CJ Commented Jul 1, 2019 at 2:10
Add a comment  | 

1 Answer 1

Reset to default 2

When you save a selected page in the Customiser you're just saving the post ID of the page, which means you can just pass that value to any function that accepts a post ID as a parameter:

$mytheme_f_page[1] = get_theme_mod( 'mytheme_featured_page_1' );

echo get_the_title( $mytheme_f_page[1] );
echo get_the_excerpt( $mytheme_f_page[1] );
echo get_the_post_thumbnail( $mytheme_f_page[1] );

The first time you use any one of these the full post (page) is cached internally, so you don't need to worry about getting them one at a time or all at once, or anything like that.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论