Main Menu
collapse

Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

SMF 2.1 users: EhPortal is a ported version of Simple Portal specifically designed for the SMF 2.1 branch.
Please visit web-develop.ca to download EhPortal and for its support.

User Info

Welcome Guest.
Please log in.

Who's Online

  • Dot Guests: 969
  • Dot Hidden: 0
  • Dot Users: 1
  • Dot Users Online:

Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]


Installation errors? Mod incompatibilities? Upgrade problems? Make your way over to the Install and Upgrade Support board for all your solutions!

Custom Pages - help

Started by The Wizard, October 29, 2010, 10:29:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

The Wizard

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


Quoteglobal $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>';

AngelinaBelle

http://www.w3schools.com/php/php_if_else.asp
http://www.php.net/manual/en/language.control-structures.php


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.

Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

The Wizard

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

AngelinaBelle

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.

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>
';



Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?

[SiNaN]

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.
And slowly, you come to realize... It's all as it should be...

The Wizard

#5
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....

Quoteglobal $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>';

The Wizard

YEA!!! Found the Answer -

Quoteglobal $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...

The Wizard

It's me again  :'(
this only works with one page....
I wanted it to sort more them one page....

ccbtimewiz

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.

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>';

The Wizard

Quoteglobal $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.

The Wizard

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

ccbtimewiz

I don't see why you even need to use count() for... what are you trying to do?

The Wizard

Quoteglobal $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.

The Wizard

Quote from: 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?

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

AngelinaBelle

#14

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>';
Please to keep this website running, if you like SimplePortal, make a
one-time subscription. Thank you for your support.

Have you tried the SimplePortal documentation?