Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QUESTION PHP - getting tags for each page in an array
#1
Hi, I hope I've come to the right place for a little help with PHP that i'm using on GetSimple. Thank you for taking the time to read this. Smile

I have a Getsimple install which I'm using for my personal site. My intention is to have a single front page with all articles I've added. I would then like to have two pages one which shows all articles with the tag 'code' and another for 'writing' to separate the articles a bit more.

I have the following code to pull the pages onto the front page, which i'm happy with:

PHP Code:
<?php
          
global $pagesArray;
          
$pagesSorted subval_sort($pagesArray,'menuOrder'); // or 'title', 'menu', 'url', ...
          
foreach ($pagesSorted as $page
            if (
$page['url']!='index' 
              
&& $page['menuStatus']=='Y'){
                
$pag $page['url'];
              
?>
              <a name="<?php echo $pag?>"></a>
              <div class="pagecontent <?php echo $pag?>">
                  <a href="<?php echo $pag?>"><h2><?php getPageField($pag,'title'); ?> </h2></a>
                  <?php getPageContent($pag); ?>
                 </div>
              <?php 
            

          
?>

My question is how do i add the "contains tag 'code' to the if statement so that i can further filter the pages for the page called 'code' that will show all of the other pages tagged with 'code'.

I hope that makes sense, any help would be greatly appreciated, and please let me know if i need to provide more information.

thank you,

Chris.
Reply
#2
If I understand correctly, you could just add "code" to meta keywords of each page that should be marked so and then simply pull all pages that have "code" in their meta field.

Edit: ok, I get it. I think... How about this?
PHP Code:
<?php
global $pagesArray;
$pagesSorted subval_sort($pagesArray,'menuOrder'); // or 'title', 'menu', 'url', ...

foreach( $pagesSorted as $page )
{
    if( 
$page['url'] != 'index'
        
&& $page['menuStatus'] == 'Y'
        
&& strposstrtolower$page['meta'] ),'code' ) !== false )
    {
        
$pag $page['url'];
?>
        <p>contains 'code' tag</p>
        <a name="<?php echo $pag?>"></a>
        <div class="pagecontent <?php echo $pag?>">
            <a href="<?php echo $pag?>"><h2><?php getPageField$pag,'title' ); ?> </h2></a>
            <?php getPageContent$pag ); ?>
        </div>
<?php ?>
Reply
#3
Hi Everyone (sounds funny! Smile ),

thanks for your response, that looks like it might be perfect. I'll give it ago when i get home later.

To use that, can i add the 'code' to the tags field in the page edit screen, or will i need to add it into the template that the pages use?

Edit: tried it with the tags added directly to the pages screen and adding the code to the template and it has worked a treat. spot on, thank you.

Thanks again,

Chris.
Reply




Users browsing this thread: 1 Guest(s)