如何在get_pages中获取数组中的页面ID?

时间:2011-02-07 05:33:40

标签: wordpress

如果我有3个喜欢

的ID
$page1 = get_option('home_page_field');
$page2 = get_option('home_page_field1');
$page3 = get_option('home_page_field2');
$page4 = get_option('home_page_field3');
$arrData = array( $page1, $page2 , $page3 );

给予o / p

Array ( [0] => Array ( [text_string] => 2 ) [1] => Array ( [text_string] => 499 ) [2] => Array ( [text_string] => 869 ) )

如何设置get_pages函数以获取有关这些页面ID的页面的所有信息

请帮助谢谢

2 个答案:

答案 0 :(得分:0)

请参阅:http://codex.wordpress.org/Function_Reference/get_page

<?php print_r(get_page( $page_id )) ?>

试试这个

$pages = array();
foreach($arrData as $item){
   $pages[(int)$item['text_string']] = get_page((int)$item['text_string']);
}
print_r($pages);

答案 1 :(得分:0)

我用过这个过去并发现它非常有用,因为你得到了网页的所有内容:

$mypages = get_pages( array( 'parent' => $post->ID ) );
// you could put any ID here, or any of the page identifiers in the get_pages function (https://codex.wordpress.org/Function_Reference/get_pages)

foreach( $mypages as $page ) {      
    $content = $page->post_content;
    if ( ! $content ) // Check for empty page
        continue;

   $content = apply_filters( 'the_content', $content );
?>
//This allows you to access any of the content on these pages, like this:

<div style="background-image: url('<?php echo get_the_post_thumbnail_url( $page, 'post-thumbnail' ) ?>'); ">"
    <p style="color: white; text-transform: uppercase;"><?php echo $page->post_title; ?></p>
</div>

这种情况的不同变化在过去帮助了我很多 - 让我知道它是否能满足您的需求!

-Alyssa