Author Topic: Global blocks - or how to get the same content on every page  (Read 55662 times)

pcwacht

  • Guest
Global blocks - or how to get the same content on every page
« on: January 08, 2006, 03:55:48 PM »
What you need to do to make the 'globalblocks' work:

1 - the 'blank' template wich come with wb26x, it has only <?php page_content(); ?> in it's index.php, nothing more, this will be the template for the globalblocks
2 - make a menuitem 'blocks' and set it hidden (this will be the place to store the blocks)
3 - make a new page, 'block1', choose the 'blank' template for it, choose the 'blocks' page as parent and give it the content you want
4 - same as 3 for the second 'globalblock' and call this 'block2'
5 - change your current template's index.php by adding the two pages you just made

<?php include (WB_URL."/pages/blocks/block1.php"); ?> and
<?php include (WB_URL."/pages/blocks/block2.php"); ?>
 at the position you want it.

What it does:
You made 2 pages, block1 and block2 and you choose the minimalistic template for it, so when you call those pages in your browser (http://yourdomain/pages/blocks/block1.php (or block2.php) you only will see what you entered, nothing more!

By including those two blocks in your template, the output will be placed in your normal pages at the place you have put the include-code.

That's basicly it.
Nothing fancy, nothing tricky, just using the system.

Benefits are:
one block for all pages
one time edit to change a block
much easier to admin
and it will show up in the search page (allso in the news-comments pages)

« Last Edit: January 08, 2006, 04:02:36 PM by pcwacht »

Offline rabsaul

  • Posts: 271
    • http://www.pactumgroup.com
Re: Global blocks - or how to get the same content on every page
« Reply #1 on: February 27, 2006, 11:03:27 AM »
One thing you don't mention here is how to edit these blocks. Are they visible and editable from the Pages section of the Admin, or do they need to be edited manually?

Thanks!

Offline wwwMARKLEYcouk

  • Posts: 287
  • Gender: Male
    • Markley IT & Storage
Re: Global blocks - or how to get the same content on every page
« Reply #2 on: February 27, 2006, 11:10:45 AM »
One thing you don't mention here is how to edit these blocks. Are they visible and editable from the Pages section of the Admin, or do they need to be edited manually?

Thanks!
they will show up in the pages section as number 3 states:

Quote from: pcwacht
3 - make a new page

Offline rabsaul

  • Posts: 271
    • http://www.pactumgroup.com
Re: Global blocks - or how to get the same content on every page
« Reply #3 on: February 28, 2006, 09:14:42 AM »
They work great! Excellent! :)

Offline kibmcz

  • Posts: 237
  • Gender: Male
    • KComputer  Zone
Re: Global blocks - or how to get the same content on every page
« Reply #4 on: March 05, 2006, 12:13:36 PM »
when i put <?php include (WB_URL."/pages/blocks/block1.php"); ?> in my template i am locked out of executing php in the current path (eg. http://www.yourdomain.com/)  for a random times. Yet my blog at /blog still worked ?
« Last Edit: March 05, 2006, 12:57:30 PM by kibmcz »

pcwacht

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #5 on: March 05, 2006, 01:22:18 PM »
might be due to the code in your block1 page

try only an echo 'Hello world'; to test this.

John

Offline kibmcz

  • Posts: 237
  • Gender: Male
    • KComputer  Zone
Re: Global blocks - or how to get the same content on every page
« Reply #6 on: March 05, 2006, 01:45:38 PM »
might be due to the code in your block1 page

try only an echo 'Hello world'; to test this.

John

Thanks that helped... it was the WYSIWYG module. it dosn't work in the global block. Not a prob as long as form module works (and it does).

kickarse

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #7 on: April 18, 2006, 04:44:16 PM »
Good idea! I think I'm going to use this on a site I'm developing now.

Offline Wirus

  • Posts: 6
Re: Global blocks - or how to get the same content on every page
« Reply #8 on: May 09, 2006, 12:47:51 PM »
Is possible make second block without absolute path ?

Defined NOT as:
<?php include (WB_URL."/pages/blocks/block2.php"); ?>

but something like this:
<?php include ("../pages/blocks/block2.php"); ?>

Absolute url fopen is often forbiden by server...

Thanks
« Last Edit: May 09, 2006, 12:55:19 PM by Wirus »

pcwacht

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #9 on: May 09, 2006, 01:02:38 PM »
Don't think it can be done

I tried to but got warnings about missing config(.)php in the called file


But why do you need it?

John

Offline Wirus

  • Posts: 6
Re: Global blocks - or how to get the same content on every page
« Reply #10 on: May 10, 2006, 08:44:13 AM »
Including complete URL is forbiden on my server. (security hole) I can include only local path. This is possible but system dont change template of included page (is set to blank) and include it with template of actual page (round).

pcwacht

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #11 on: May 10, 2006, 10:59:49 AM »
Have you seen my other solution?
This don't need path's etc...

http://forum.WebsiteBaker.org/index.php/topic,3217.0.html

Another option would be to abslote the link, something like /home/somepath/http/pages/page12.php


John

Offline rabsaul

  • Posts: 271
    • http://www.pactumgroup.com
Re: Global blocks - or how to get the same content on every page
« Reply #12 on: May 11, 2006, 11:09:56 PM »
Is possible make second block without absolute path ?

Defined NOT as:
<?php include (WB_URL."/pages/blocks/block2.php"); ?>

but something like this:
<?php include ("../pages/blocks/block2.php"); ?>

Absolute url fopen is often forbiden by server...

Thanks
That's not an absolute path. An absolute path would be http://www.etcetc.

pcwacht

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #13 on: May 12, 2006, 12:16:27 PM »
Quote
That's not an absolute path. An absolute path would be http://www.etcetc.

Path = filebased
URL is webserver based

http://www.somedomain.com/somepath/somefile.php = absolute url
/home/sites/site300/web/somepath/somefile.php = absolute path (on linux)
../somepath/somefile.php = relative (path or url)


John

Offline DGEC

  • Posts: 388
  • Gender: Male
    • EbelTech homepage
Re: Global blocks - or how to get the same content on every page
« Reply #14 on: June 21, 2006, 10:48:00 PM »

                    ....
5 - change your current template's index.php by adding the two pages you just made

<?php include (WB_URL."/pages/blocks/block1.php"); ?> and
<?php include (WB_URL."/pages/blocks/block2.php"); ?>
 at the position you want it.


One suggestion about this code: rather than using the literal  /pages/, everyone should probably get in the habit of using the WB_PATH variable, especially for templates, snippets, modules, etc. That way if someone has a different path or no path, your brilliant code will still work  :-D

So instead of:

     
Code: [Select]
<?php include (WB_URL."/pages/blocks/block1.php"); ?>
you would instead code  (I think - this isn't tested yet)

     
Code: [Select]
<?php include (WB_URL WB_PATH "/blocks/block1.php"); ?>

eddyfever

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #15 on: February 21, 2007, 06:51:16 PM »
So strange this never with me, it looks like it is not alloud to insert a .php or something.
does anybody know what it can be.

preview: under title (poll)
http://www.rawrock.nl/site

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #16 on: February 21, 2007, 06:56:46 PM »
if it does not work, try curl instead:

Code: [Select]
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, WB_URL.'/pages/pagename.php');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
// display file
echo $file_contents;

cheers

Klaus

eddyfever

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #17 on: February 21, 2007, 07:03:58 PM »
can you maybe explain how i can use this?

Nevermind: it works with your solution!!!!

Vielen herzlichen Dank. Abende lang hab ich gesucht und endlich hat es geklappt!!!!!!!
« Last Edit: February 21, 2007, 07:08:53 PM by eddyfever »

eddyfever

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #18 on: February 21, 2007, 07:27:43 PM »
And when i use more blocks in my template do i have to change then something in the script?
this because now it doesnt load theright site of my template when i use it more times in my template.
« Last Edit: February 21, 2007, 07:35:06 PM by eddyfever »

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #19 on: February 22, 2007, 07:30:42 AM »
Hmm... haven't tried it yet multiple times (no need to). For which types of info do you still need it?

cheers

Klaus

aggiedad

  • Guest
Re: Global blocks - or how to get the same content on every page
« Reply #20 on: June 07, 2007, 05:24:08 AM »
Can this be used with more than two blocks?

I was trying this technique with more than two blocks and it caused my site to hang-up. First I tried it by just adding an additional block. Then when that didn't work, tried a second hidden page -- things still didn't work.

Any thoughts?

Thanks!

Don Simmons
Texas

Offline weiry

  • Posts: 92
Re: Global blocks - or how to get the same content on every page
« Reply #21 on: January 06, 2009, 07:23:46 AM »
if it does not work, try curl instead:

Code: [Select]
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, WB_URL.'/pages/pagename.php');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
// display file
echo $file_contents;

cheers

Klaus
Thank you for this option Klaus. No matter what I did, I couldn't get it to work with the other options, even after reading numerous related threads. But this curl worked straight away.

Cheers.

Offline sare

  • Posts: 29
Re: Global blocks - or how to get the same content on every page
« Reply #22 on: January 30, 2009, 10:44:51 AM »
Same here.

Nothing worked with the normal include, at best it showed the wrong template with the include and broke all page_content-functions that were after that in the template code.

This cURL code worked like magic after finding the right URL for it to use.

If you can't get the cURL code to work, try with and without the www-part in the WB_URL. I didn't use it at first, and got 404's (not found).

Hope this saves somebody else the 3 hours I spent scrathing my head...

Offline kweitzel

  • WebsiteBaker Org e.V.
  • **
  • Posts: 6983
  • Gender: Male
Re: Global blocks - or how to get the same content on every page
« Reply #23 on: January 30, 2009, 11:15:03 AM »
Since cURL is actually an Wrapper for URLs you obviously will need to feed it with an URL and not a path. It will also only work, if it is activated on the Server.

cheers

Klaus

Offline masju

  • Posts: 132
  • Gender: Male
Hi!

If your server does not allow the include-command in your template's index.php
<?php include (WB_URL."/pages/blocks/block1.php"); ?>
due to security-settings, try this instead:

<?php
$handle = fopen (WB_URL."/pages/blocks/block1.php", "r");
while (!feof($handle))
   {
    $buffer = fgets($handle, 4096);
    print_r ($buffer);
   }
 ?>

Works well :-)

greets masju

 

postern-length