I am trying to do something very characteristic and i am not that kinda good with PHP.
I am making some site for soccer team. And i want to have one main page called RESULTS. I will have for example 10 rounds(every round have separate page) in full season. I already make fixtures and everything depending on date.
My problem is how to call specific page, for example today is 29.10.2013 and my 3rd round has just over and i fill out all my result on my "3rd round page", and i want that this content be shown on page "RESULTS" also.
Than next week 04.11.2013 its coming my 4th round and i will also fill out everything on my "4th round page", but i just want now that all this be on "RESULTS" page because this is active round now not 3rd round.
I am guessing that i need to make template for my "RESULTS" page but i just need code, function how to call specific ID page depending on date. (29.10.2013 call page id 54; 04.11.2013 call page id 55). I hope i explained well and hope someone is good in this. Thanks in advance!
If you want to get the data of a specific page you can use "get_posts"
http://codex.wordpress.org/Template_Tags/get_posts
Inside your page template add something like this
<ul>
<?php
$args = array( 'posts_per_page' => -1,
'post_type' => 'page',
'include'=> $THE_PAGE_ID
);
$myposts = get_posts( $args );
foreach ( $myposts as $post ) :
setup_postdata( $post );
?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php
endforeach;
wp_reset_postdata();
?>
</ul>
Or use "get_post":
http://codex.wordpress.org/Function_Reference/get_post
<?php
$thepost = get_post($THE_PAGE_ID, ARRAY_A);
$title = $thepost['post_title'];
echo $title;
?>
Hope that's what you where after.
Thanks a lot for reply, i see that you very good with this. I did like you tell me and with this i got link to page on my "RESULTS" page.
So is it possible to little bit change code that will be checking date. For example:
check date,
if date is 29.10.2013->call content(not link)of page ID=2
if date is 30.10.2013->call content of page ID=3
if date is 31.10.2013->call content of page ID=4
I would do it myself but i am not even close good with this like you. So sorry for being boring but i really need to learn this stuff.
This is probably not the most elegant answer but should work
<?php
switch(date('d.m.Y'))
{
case '29.10.2013':
$THE_PAGE_ID = 1;
break;
case '29.10.2013':
$THE_PAGE_ID = 2;
break;
case '29.10.2013':
$THE_PAGE_ID = 3;
break;
default:
$THE_PAGE_ID = 4; // page if the date does not match
}
$args = array( 'posts_per_page' => -1,
'post_type' => 'page',
'include'=> $THE_PAGE_ID
);
$myposts = get_posts( $args );
foreach ( $myposts as $post ) :
setup_postdata( $post );
?>
<h1><?php the_title(); ?></h1>
<div id="page-content">
<?php the_content(); ?>
</div>
<?php
endforeach;
wp_reset_postdata();
?>