Welcome to Geeklog, Anonymous Thursday, March 28 2024 @ 02:32 pm EDT

Geeklog Forums

Want to create a BLOCK that displays content in the center.

Page navigation


Zewt

Anonymous
I am somewhat skilled in PHP, and understand how to create blocks and add the function to the custom_lib.

What I am not good at is understanding templates.

I want to add blocks that display their output in the center column (or left/right etc.) of the geeklog mainpage.

Can someone point me at an example of how I would do this, or maybe give me a basic description?

Thank you for any help.
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Quote by Zewt: I want to add blocks that display their output in the center column (or left/right etc.) of the geeklog mainpage.

For the center column, use a static page (and select "centerblock" in the options).

For left/right blocks, just create a PHP block. See What are the different block types for?

bye, Dirk
 Quote

Zewt

Anonymous
Ok. I understand about creation of static pages, so if I create a custom php page to say display a list of friends.

How do I reference that PHP page so that it will be executed into the static page?

Assume that the php page is friends.php.

Or do I past the php code into the static page?
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Quote by Zewt: Or do I past the php code into the static page?

That's how PHP in static pages works.

Or you could include your file from the static page's PHP.

bye, Dirk
 Quote

Zewt

Anonymous
Thanks Dirk. After reading that page on static pages and doing some tests, it all becomes clearer.

Apparently I can use the PHP include(), and so forth if needed.

I am just trying to link to a much larger, complex, back-end database system, and some code pages are large.
 Quote

Zewt

Anonymous
Ok I have one more question, I think.

I want to have a link on the left that displays the static page on clicking.

So I tried creating a custom block that had a link to the static page.

The link works, but only if the static page is set to be automatically displayed as centerblock.

I do not want the static page to be displayed unless the link is clicked. And as it is currently the static page is always there when the home page is first loaded.

Any tips on what I am missing to do this?
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 01/12/02
Posts: 13073
Location:Stuttgart, Germany
Quote by Zewt: I do not want the static page to be displayed unless the link is clicked.

Hmm, I don't think that's possible at the moment.

You could do that with a side block, since the block would not be displayed when it returns an empty string (so the PHP code in the block could decide when it should be displayed or not). For static pages, however, Geeklog always adds the block header and footer, even if the page is empty.

Shouldn't be too hard to change, though (in the plugin's functions.inc).

bye, Dirk
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
Quote by Dirk:however, Geeklog always adds the block header and footer, even if the page is empty.
what if you unchecked the "wrap static page in a block" option in the staticpages editor. ...and then if you still want that look, just add similar html to the staticpage.
 Quote

Status: offline

jhk

Forum User
Chatty
Registered: 07/13/02
Posts: 57
nerdy
Quote by Zewt: I do not want the static page to be displayed unless the link is clicked. And as it is currently the static page is always there when the home page is first loaded.

What you need is DHTML. Smile

Don't wrap the staticpage in a block, but make it active on all pages as a centerblock. Put a DIV with a unique ID around all of the centent and make your side-block link hide and un-hide the DIV via Javascript. You can even set a cookie to save the preference for each user/pc.

I do something slightly similar on one of my staticpages, which is currently not used as a centerblock. It will be in a week a so. There are 30-odd DIVs hidden in that staticpage. (The buttons read "Matches yesterday", "Matches today", and "Matches tomorrow". The football season has not yet started, so until it does the block is not used. The dropdown menu works like a charm, however).

/Jens
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
here ya go. I did it for you and didn't use any java script.
I used one php enable static page (not wrapped in a block), which can include a range of blocks/pages depending upon the link that is clicked.
I inserted the block footer divider so that it still looks somewhat like it is wrapped in a block.

try it here. just look for the links in the left column--"display blocks"--and click accordingly. by default no centerblock is displayed and when you click, viola, content appears.

the links include a get parm and here is the staticpage php.
Text Formatted Code
if (empty($_GET['blk'])){
    return '';
} else {
    $retval .= <div class="centerblock">
    $retval .= '<p>This is a static page centerblock set to display on the';
    $retval .= ' homepage only.  Using a bit of PHP, it should only be';

    $retval .= ' viewable when the appropriate link is clicked.  This';
    $retval .= ' block is designated ';
    if ($_GET['blk'] == 'st1'){
        //you can call other blocks here or just different code--whatever.
        $retval .= '<strong>BLOCK #1</strong>.';
    } elseif ($_GET['blk'] == 'st2'){
        //you can call other blocks here or just different code--whatever.
        $retval .= '<strong>BLOCK #2</strong>.';
    } elseif ($_GET['blk'] == 'st3') {
        //you can call other blocks here or just different code--whatever.
        $retval .= '<strong>BLOCK #3</strong>.';
    }
    $retval .= '  Click the other block links to see the block change.</p>';
    $retval .= '</div>';
    $retval .= '<table class="block-divider" align="center" cellpadding="0" cellspacing="0" width="100%"><tr><td><img src="http://themes.summitpages.ca/images/speck.gif" alt="" height="2" width="1"></td></tr></table>';

    return $retval;
}

 
 Quote

Status: offline

jhk

Forum User
Chatty
Registered: 07/13/02
Posts: 57
machinari,

Did you user a PHP block or a regular one? With PHP I think it would be possible to combine the links with previous parameters via $_SERVER[QUERY_STRING'] and similar variables.

/Jens
 Quote

mach

Anonymous
yup, just a normal block for the sake of the example, but if i wanted to be more practical, then yes, a php block would be the way to go
 Quote

Zewt

Anonymous
Very nice.

I am new to GL, and was hoping it had the flexibility without extra coding. It looks though as if I will be needing to dive in to modify for my wants.

Thank you for all the feedback. Im sure I will be needing to get all kinds of great help for future mods, nice to see all the great help here.
 Quote

Zewt

Anonymous
Im not sure I understand how one static page can have multiple blocks Shocked

Can you post the code for that one static page?
 Quote

Zewt

Anonymous
Cannot seem to find what is causing this error


Parse error: parse error in C:Websiteshackpackpluginsstaticpagesfunctions.inc(475) : eval()'d code on line 4
 Quote

Zewt

Anonymous
Ok found the problem.

some single quotes and a semicolon are missing from a line, I think the code for this chat board is removing some of the code.
 Quote

Zewt

Anonymous
Here I have modified the code to add a fourth item, that uses an INCLUDE

Text Formatted Code
if (empty($_GET['blk'])){
    return '';
} else {
    $retval .= '<div class="centerblock">';
    $retval .= '<p>This is a static page centerblock set to display on the';
    $retval .= ' homepage only.  Using a bit of PHP, it should only be';
    $retval .= ' viewable when the appropriate link is clicked.  This';
    $retval .= ' block is designated ';
    if ($_GET['blk'] == 'st1'){
        //you can call other blocks here or just different code--whatever.
        $retval .= '<strong>BLOCK #1</strong>.';
    } elseif ($_GET['blk'] == 'st2'){
        //you can call other blocks here or just different code--whatever.
        $retval .= '<strong>BLOCK #2</strong>.';
    } elseif ($_GET['blk'] == 'st3') {
        //you can call other blocks here or just different code--whatever.
        $retval .= '<strong>BLOCK #3</strong>.';
    } elseif ($_GET['blk'] == 'st4') {
        //you can call other blocks here or just different code--whatever.
        include ($_CONF['site_url'].'/teetime.php');
    }
    $retval .= '  Click the other block links to see the block change.</p>';
    $retval .= '</div>';
    $retval .= '<table class="block-divider" align="center" cellpadding="0" cellspacing="0" width="100%"><tr><td</td></tr></table>';

    return $retval;
}
 


Notice the fix for line 4, using single quotes and a semicolon at the end of the line.

Thanks for the code work MACHINARI, it has helped me start to unravel how GL can work for my application. Very Happy
 Quote

Status: offline

jhk

Forum User
Chatty
Registered: 07/13/02
Posts: 57
Quote by Zewt: Im not sure I understand how one static page can have multiple blocks Shocked

Can you post the code for that one static page?

That particular page has 169 lines of php with an additional 133 lines in lib-custom.php and a further 102 lines of Javascript. I'm not sure posting the code is feasable - or even useful to you as there is a lot of site specific code there as well as some php caching (using PEAR Cache.php). Very Happy

The key to the whole thing is a Switch Content script I downloaded and adapted for my own use. Take a look at that page for instructions and inspiration.
 Quote

Zewt

Anonymous
Here is the code for the static page:
ID is blk.

Text Formatted Code
if (empty($_GET['blk'])){
    return '';
} else {
    $retval .= '<div class="centerblock">';
    //$retval .= '<p>This is a static page centerblock set to display on the';
   // $retval .= ' homepage only.  Using a bit of PHP, it should only be';
   // $retval .= ' viewable when the appropriate link is clicked.  This';
    //$retval .= ' block is designated ';
    if ($_GET['blk'] == 'st1'){
        //you can call other blocks here or just different code--whatever.
        $retval .= '<strong>BLOCK #1</strong>.';
    } elseif ($_GET['blk'] == 'st2'){
        //you can call other blocks here or just different code--whatever.
        $retval .= '<strong>BLOCK #2</strong>.';
    } elseif ($_GET['blk'] == 'st3') {
        //you can call other blocks here or just different code--whatever.
        $retval .= '<strong>BLOCK #3</strong>.';
    } elseif ($_GET['blk'] == 'st4') {
        //you can call other blocks here or just different code--whatever.
        include ($_CONF['site_url'].'/teetime.php');
    }
    //$retval .= '  Click the other block links to see the block change.</p>';
    $retval .= '</div>';
    $retval .= '<table class="block-divider" align="center" cellpadding="0" cellspacing="0" width="100%"><tr><td</td></tr></table>';

    return $retval;
}
 


Here is the function I added to lib-custom.php

Text Formatted Code

function phpblock_rapp_test2() {

    global $_CONF, $_TABLES, $_USER, $LANG01;

    $retval = '';

    $retval .= '<a href="'.$_CONF['site_url'].'/index.php?blk=st1">Mather Mon.</a>';
    $retval .= '<a href="'.$_CONF['site_url'].'/index.php?blk=st2">Landpark Tues.</a>';
    $retval .= '<a href="'.$_CONF['site_url'].'/index.php?blk=st3">Landpark Wednesday.</a>';
    $retval .= '<a href="'.$_CONF['site_url'].'/index.php?blk=st4">TEST</a>';
   
    return $retval;
}

 


you then need to create a BLOCK to call the custom function:
The BLOCK TYPE needs to be: PHP BLOCK
and the BLOCK FUNCTION needs to be: phpblock_rapp_test2


I'm setting up something to display tee times, sorry if my labels suck as decriptions.

Also for the blk=4 part, you need to create a basic php page called teetime.php.

you can use this code if you like:


Text Formatted Code

<?php

// This is teetime.php

print "CUSTOM INCLUDED PAGE"

?>

 
 Quote

Zewt

Anonymous
It is definitely better to use PHP vs. DHTML.

What the code listed above is doing is basic PHP. Basically passing a variable using the URL.

this part
Text Formatted Code
index.php?blk=st4
 
that you see in the URL is where blk is being made a variable, and being assigned the value of st4.

The ? in
Text Formatted Code
index.php?blk=st4
 
is telling PHP that the next characters will be a variable, and the = is assigning st4 to blk.

What happens next is in the PHP code of the static page.

this line:
Text Formatted Code
if (empty($_GET['blk'])){
 

is looking at the variable blk. The
Text Formatted Code
$_GET[***]
 
part is a PHP built in global variable function.

The
Text Formatted Code
$_GET['blk']
 
is the part that retrieves the value in
blk.

you could just get the value in BLK once by assigning it to a new variable.

such as
Text Formatted Code
$testvar = $_GET['blk']
 

Now just use
Text Formatted Code
$testvar
 
instead of
Text Formatted Code
$_GET['blk']
 
everytime.
 Quote

Page navigation

All times are EDT. The time is now 02:32 pm.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content