Posts: 47
Threads: 7
Joined: Dec 2016
I want to select some created pages according to their creation date and values of some other fields and insert their title and creation date (and maybe some other meta information) with links to every respective page in another page. I want that content of the destination page is provided automatically, that is if a page is created that meets criteria its title etc. appears in the destination page and when the criteria cease to be valid (a time elapses) it disappears from it (shortly, I want imitate official notice board).
I know that information about all pages is stored in $pagesArray array so I can obtain information from there and write some function that selects desired pages. But there are two things that I don't know: where should I place such function and how I insert the result of that function in the destination page?
Posts: 538
Threads: 12
Joined: May 2013
2017-08-07, 00:42:40
(This post was last modified: 2017-08-07, 00:43:39 by Bigin.)
- /theme/your-theme-directory/functions.php
- /theme/your-theme-directory/template.php:
PHP Code:
if(get_page_slug(false) == 'your-page-slug') {
// display at runtime
echo your_function();
}
Posts: 47
Threads: 7
Joined: Dec 2016
Posts: 47
Threads: 7
Joined: Dec 2016
(2017-08-07, 00:42:40)Bigin Wrote:
- /theme/your-theme-directory/functions.php
- /theme/your-theme-directory/template.php:
PHP Code:
if(get_page_slug(false) == 'your-page-slug') {
// display at runtime
echo your_function();
}
I have a problem with your advice.
Before I asked my question I put my function for testing purpose into the
sidebar.inc.php and it works well (the function displays what I want in the sidebar). But if I put the function in the template file almost nothing displays in a page and there is only a notice and a warning in the debug mode:
Notice: Undefined variable: pagesArray in /var/www/html/ret/theme/Innovation/functions.php on line 53,
Warning: Invalid argument supplied for foreach() in /var/www/html/ret/theme/Innovation/functions.php on line 53.
(I have
foreach ($pagesArray as $key => $value) { on line 53).
So, the function knows the variable
$pagesArray if located in
sidebar.inc.php but doesn't know it if located in
template.php. How can I fix it?
Posts: 538
Threads: 12
Joined: May 2013
2017-08-10, 18:30:42
(This post was last modified: 2017-08-10, 18:37:48 by Bigin.)
Probable your foreach() construct is wrapped in a function call:
PHP Code:
your_function() {
foreach($pagesArray as $key => $value) {
...
}
You'll need to make the $pagesArray available locally:
PHP Code:
your_function() {
global $pagesArray;
foreach($pagesArray as $key => $value) {
...
}
But this is really basic knowledge
Posts: 47
Threads: 7
Joined: Dec 2016
Yes, I realized almost immediately that I put only a sequence of commands in the sidebar.inc.php, not a function. So, I am sorry for a hasty question.
Posts: 538
Threads: 12
Joined: May 2013