SimplePortal

Customization => Custom Coding => Topic started by: The Wizard on October 29, 2010, 10:29:07 PM

Title: Custom Pages - help
Post by: The Wizard on October 29, 2010, 10:29:07 PM
Hello:
I'm still new to php and need some help with this. I want to make a custom php block that will list the pages I have created. Below is the code I have found posted by the master builder of SP. This works great, but I need it to only list certian pages. I figure I can pull this off by creating pages I want to list togeter by giving them the same starting title.
Example - Football players, Football Teams, ect...
If someone could modify/add the code I would need to make this happen it you would make my day.  :thumbsup:

Thank you


Quote
global $scripturl;$pages = sportal_get_pages(null, true);echo '<ul>';foreach ($pages as $page)   echo '   <li><a href="', $scripturl, '?page=', $page['page_id'], '">', $page['title'], '</a></li>';echo '</ul>';
Title: Re: Custom Pages - help
Post by: AngelinaBelle on November 01, 2010, 12:52:54 PM
http://www.w3schools.com/php/php_if_else.asp (http://www.w3schools.com/php/php_if_else.asp)
http://www.php.net/manual/en/language.control-structures.php (http://www.php.net/manual/en/language.control-structures.php)
 
Code: [Select]
global $scripturl;
$pages = sportal_get_pages(null, true);
echo '<ul>';
 
foreach ($pages as $page) 
{
    if (....)
        echo '   <li><a href="', $scripturl, '?page=', $page['page_id'], '">', $page['title'], '</a></li>';
}
 
echo '</ul>';

Only -- you need to replace the '....' with the conditions you want to use to control which pages you want to see. Look in function sportal_get_pages to see what information the function returns, and construct a logical expression to use that information the way you want to use it.
 
 
Title: Page ID
Post by: The Wizard on November 02, 2010, 08:10:57 AM
Hello:

I was wondering what - Page ID is? Exactly what would you use it for?
I'm guessing it might be some kind of script calling feature?
I have searched the forum, and it's not really explained so I thought I would ask

Please forgive me if this post is in the wrong place I was not sure where to post it.

Thnaks
Title: Re: Page ID
Post by: AngelinaBelle on November 02, 2010, 11:29:23 AM
Grasshopper, it is within yourself to answer this question.
 
It is a natural next-step as you figure out how to solve the puzzle you created in your previous topic, and could have been written as a reply to that topic.
 
Here is my suggestion: look at the information available about simpleportal pages in order to gain enlightenment about how SimplePortal keeps track of pages.
 
For example, you can copy this code into a custom php block and hit the preview button to see some of the information about pages.  If you are curious about more of the information about pages, look at the function sportal_get_pages to see which information it retrieves about the pages.
Code: [Select]
global $scripturl;
$pages = sportal_get_pages(null, true);
echo '<ul>
';
 
foreach ($pages as $page) 
{
           echo '   <li>page_id: ', $page['page_id'], ', title', $page['title'], '</li>
';
}
 
echo '</ul>
';

 
 
Title: Re: Page ID
Post by: [SiNaN] on November 02, 2010, 11:36:15 AM
Page Id is an alphanumeric id unique to every page used as an alternative to numeric ids. For example the Blocks In Blocks Sample page here can be accessed by both the page id and regular id:

http://simpleportal.net/index.php?page=blocks_in_block_sample
http://simpleportal.net/index.php?page=4

An alphanumeric id would be useful if you are using something like Simple SEF or Pretty URLs to display pretty links for pages easily. It looks prettier than numeric ids.
Title: Re: Custom Pages - help
Post by: The Wizard on November 02, 2010, 01:02:02 PM
Ok I'm close on this I thnk but I still need a help/push off cliff...
What I posted below lists all the pages and not just the one I want, but all the links goto the page I want. So whats the problem? Lost sole....

Quote
global $scripturl;
$pages = sportal_get_pages(null, true);
echo '<ul>';

foreach ($pages as $page)
if ($page['page_id']='superman') {
echo ' <li><a href="', $scripturl, '?page=', $page['page_id'], '">', $page['title'], '</a></li>';

}
echo '</ul>';
Title: Re: Custom Pages - help
Post by: The Wizard on November 02, 2010, 01:18:43 PM
YEA!!! Found the Answer -

Quote
global $scripturl;
$pages = sportal_get_pages(null, true);
echo '<ul>';

foreach ($pages as $page)
if ($page['page_id']=='superman') {
echo ' <li><a href="', $scripturl, '?page=', $page['page_id'], '">', $page['title'], '</a></li>';

}
echo '</ul>';

I did not have two == ahhhhh
anyway above is the completed code for all those that follow me...
Title: Re: Custom Pages - help
Post by: The Wizard on November 02, 2010, 01:26:06 PM
It's me again  :'(
this only works with one page....
I wanted it to sort more them one page....
Title: Re: Custom Pages - help
Post by: ccbtimewiz on November 02, 2010, 01:55:58 PM
I have expanded your code for multiple pages. To add more, simply append a new line into the array, surrounded by single quotes, and with a comma at the end.

Code: [Select]
global $scripturl;
$pages = sportal_get_pages(null, true);
echo '<ul>';

$pages_to_show = array(
'superman',
'someotherpage',
'etcjustkeepaddingyourpageshere',
);

foreach ($pages as $page)
{
if (in_array($page, $pages_to_show))
echo ' <li><a href="', $scripturl, '?page=', $page['page_id'], '">', $page['title'], '</a></li>';

}
echo '</ul>';
Title: Re: Custom Pages - help
Post by: The Wizard on November 02, 2010, 02:09:24 PM
Quote
global $scripturl;
$pages = sportal_get_pages(null, true);
echo '<ul>';
foreach ($pages as $page)
for ($n = 0; $n < count($pages);
$n++){
if ($page['page_id']=='who'."$n") {
echo ' <li><a href="', $scripturl, '?page=', $page['page_id'], '">', $page['title'], '</a></li>';
}
}
echo '</ul>';

Here is a new and inproved code. I added a counting code in. Now all you have to do is title your page ids - example who1, who2, who3, ect and it will list all those pages and display links to them.
 
Title: Re: Custom Pages - help
Post by: The Wizard on November 02, 2010, 02:21:02 PM
Note: the counting code has a flaw in it. It counts the number of pages you have created so if you have named your id a high number it will not show up. I'm working on a fix now. hope to post soon
Title: Re: Custom Pages - help
Post by: ccbtimewiz on November 02, 2010, 02:42:49 PM
I don't see why you even need to use count() for... what are you trying to do?
Title: Re: Custom Pages - help
Post by: The Wizard on November 02, 2010, 03:01:29 PM
Quote
global $scripturl;
$pages = sportal_get_pages(null, true);
echo '<ul>';

foreach ($pages as $page)
for ( $counter = 0; $counter <= 50000; $counter += 1) {

if ($page['page_id']=='who'."$counter") {
echo ' <li><a href="', $scripturl, '?page=', $page['page_id'], '">', $page['title'], '</a></li>';

}

}
echo '</ul>';

Ok this is the fixed counting code should work fine unless you have over 50,000 pages then just change the count number.
Title: Re: Custom Pages - help
Post by: The Wizard on November 02, 2010, 03:08:20 PM
I don't see why you even need to use count() for... what are you trying to do?

I have a ton of information on my BB and want to organize it into easy to find web pages (To be honest I don't like the articles system as it is now). I'm trying to automate the process so I don't have to work so hard.
To do this I need some way of calling up all diffrent pages into sections. I know this is not want most users need, but I do. I wish to thank everyone who helped me with this. I hope that posting my notes/code here it may help one person out later.

The Wizard
Title: Re: Custom Pages - help
Post by: AngelinaBelle on November 02, 2010, 04:18:28 PM
Code: [Select]
global $scripturl;
$pages = sportal_get_pages(null, true);
echo '<ul>';

foreach ($pages as $page)
 {

if ( substr($page['page_id'],0,2)=='who')  echo ' <li><a href="', $scripturl, '?page=', $page['page_id'], '">', $page['title'], '</a></li>';

}

echo '</ul>';
SimplePortal 2.3.8 © 2008-2024, SimplePortal