Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QUESTION A page as a host for information about other pages
#1
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?
Reply
#2

  1. /theme/your-theme-directory/functions.php
  2. /theme/your-theme-directory/template.php:
PHP Code:
if(get_page_slug(false) == 'your-page-slug') {
    
// display at runtime
    
echo your_function();

Reply
#3
Thank you.
Reply
#4
(2017-08-07, 00:42:40)Bigin Wrote:
  1. /theme/your-theme-directory/functions.php
  2. /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?
Reply
#5
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
Reply
#6
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.
Reply
#7
no problem
Reply




Users browsing this thread: 1 Guest(s)