Author Topic: Getting content from a page or making global blocks 2...  (Read 12249 times)

pcwacht

  • Guest
Getting content from a page or making global blocks 2...
« on: May 09, 2006, 02:49:29 PM »
Ok you know the deal...

You have a section wich you wanna show somewhere else?


Make a code section, paste:
Code: [Select]
// Change this to the section number you need!
$section_id = 65;

// Get requested section for requested page
$query_sections = $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = '$section_id' ");

// Make sure there is one
if($query_sections->numRows() > 0) {
$section = $query_sections->fetchRow();
$section_id = $section['section_id'];
$module = $section['module'];
require(WB_PATH.'/modules/'.$module.'/view.php');
}


If you need this GLOBAL, then add following to your template:
Code: [Select]
<?php
// Change to the number you need!
$section_id 65;

// Get requested section for requested page
$query_sections $database->query("SELECT section_id,module FROM ".TABLE_PREFIX."sections WHERE section_id = &#39;$section_id&#39; ");

// Make sure there is one
if($query_sections->numRows() > 0) {
$section $query_sections->fetchRow();
$section_id $section[&#39;section_id&#39;];
$module $section[&#39;module&#39;];
require(WB_PATH.&#39;/modules/&#39;.$module.&#39;/view.php&#39;);

?>

How to get the section number:
Open admin, pages, choose the page with the section you need
Then choose manage section and click the section you want
you will see a link in the browsers address bar like :
http://localhost/wb260/admin/pages/modify.php?page_id=40#65
the last number is the section (65 in this case - 40 is the page_id)

Have fun!
John


« Last Edit: May 09, 2006, 02:51:50 PM by pcwacht »

knop3se

  • Guest
Re: Getting content from a page or making global blocks 2...
« Reply #1 on: March 04, 2007, 02:20:45 PM »
Thanks! This works beautifully!    :-D

pcwacht

  • Guest
Re: Getting content from a page or making global blocks 2...
« Reply #2 on: March 04, 2007, 06:10:08 PM »
Glad it works for you.



Lotus

  • Guest
Re: Getting content from a page or making global blocks 2...
« Reply #3 on: February 22, 2008, 11:00:57 AM »
Worked for me aswell i think "global blocks" is a must have feature and you have done the neatest solution. Did a request for this feature.

https://forum.WebsiteBaker.org/index.php/topic,8731.0.html

Offline mikejd

  • Posts: 237
Re: Getting content from a page or making global blocks 2...
« Reply #4 on: September 17, 2008, 01:48:05 PM »
I am trying this to see if it will resolve my problem with a listing of products in a small shop page. I have a number of categories of product and have created a separate,hidden, page for each using the Bakery module. I am then trying to call each section from the hidden pages into a main shop page.

I've followed the instructions above inserting the code suggested by John into a Code section. This does then display the section from the sub-page but it doesn't show anything from sections on the main page which follow it, ie a wysiwyg section below the code section.

Offline Ruud

  • Posts: 3660
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: Getting content from a page or making global blocks 2...
« Reply #5 on: September 17, 2008, 02:05:17 PM »
The problem is that the snippet uses variable names that are also used in the page. They are getting lost.

You could try to use this module: https://forum.WebsiteBaker.org/index.php/topic,10674.0.html

It does the same as the script above, but you can add it as sections in your page.

Ruud

Offline mikejd

  • Posts: 237
Re: Getting content from a page or making global blocks 2...
« Reply #6 on: September 17, 2008, 02:25:49 PM »
Hi Ruud,
Thanks for the suggestion. I have tried this and it works but still leaves me with the problem I am trying to overcome, namely using more than one instance of Bakery on one page results in error messages appearing on the page due to constants being defined more than once.

Also it will only link to sections from pages with public visibility not from hidden pages, and I was trying to keep my products pages hidden and just import the sections.

I think I am going to have to completely rethink the way I set up the shop page, probably using sub-pages with the various categories linked from the main page.

cheers,
Mike

Offline Ruud

  • Posts: 3660
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: Getting content from a page or making global blocks 2...
« Reply #7 on: September 17, 2008, 02:50:22 PM »
Yes,

Doing this on a single page will actually load the module multiple times.
All the global block "tricks" will do that.

The only other solution is to use wrappers (iframes) and load different pages.
Using wrappers however will present other problems like reloading and scrolling within the iframe.

Ruud

Offline Gerard

  • Posts: 84
  • Gender: Male
    • Gerard Mollema
Re: Getting content from a page or making global blocks 2...
« Reply #8 on: December 25, 2008, 02:26:16 PM »
Great solution. It works fine for me. I used it for a multilingual site; a global block for a gallery of paintings (Just a normal wysiwygpage) and a list of exhibitions (type is the newsmodule)
I have one problem left: this trick seems not to work for the guestbookmodule. Has anyone an idea how to solve that?

Merry Christmas, everybody.

Regards,

Gerard

erpe0812

  • Guest
Re: Getting content from a page or making global blocks 2...
« Reply #9 on: December 25, 2008, 02:37:05 PM »
Hi,

please search the forum,

there is more than one solution for that.

rgds

erpe

Offline Gerard

  • Posts: 84
  • Gender: Male
    • Gerard Mollema
Re: Getting content from a page or making global blocks 2...
« Reply #10 on: December 25, 2008, 03:29:02 PM »
Hi Erpe,

Sure I did. Please don't think I do not do some digging before asking questions.. But did not found a suitable solution. I tried the wrappermodule wich should work using the blank template but it shows an ugly white border around the site. This was the best solution so far but I was'nt happy with it, neither will my customer do. Then I tried severall menublocks wich ended in messy menu's and strange behavior of them. They appear and disappear so I dislike to use more then one menublock. (In fact it should not any longer nessecary to use more menublocks since I use shwomenu2.) Then  I found a snippet to show the latest additions on a page. Very nice but I like to show all of them, not only the 10 latests. So finally I found the "global block" solution made by pcwacht wich is almost perfect for what I want to achieve and an very sophisticated one wich I like very much. But it  does not work for the guestbookmodul. I only wonder why. Maybe a small modification will do it all..

Regards,

Gerard
« Last Edit: December 25, 2008, 03:34:42 PM by Gerard »

Offline Ruud

  • Posts: 3660
  • Gender: Male
  • Do not use PM for help! Please use the forum!
    • Dev4Me - Professional WebsiteBaker Development
Re: Getting content from a page or making global blocks 2...
« Reply #11 on: December 25, 2008, 10:50:39 PM »
The guestbook module fetches the content using the current page_id and section_id. This way multiple guestbooks are possible  within one site.
When using the global block solution the page_id/section_id will be different. Therefore there is no content shown.

I think a wrapper solution will be your only option (unless you want to rewrite the guestbook module)

Ruud

erpe0812

  • Guest
Re: Getting content from a page or making global blocks 2...
« Reply #12 on: December 25, 2008, 11:09:17 PM »
Hi Gerard,

this guestbook is made with a wrapper and a blank template, but I know, there was another solution that I tried before, posted in the forum, and it worked well too. It based on php-code in a code section, if I remember right. But don't know the thread  anymore.

So please try the search again, I hope you will be successfull.

rgds

erpe

Offline Gerard

  • Posts: 84
  • Gender: Male
    • Gerard Mollema
Re: Getting content from a page or making global blocks 2...
« Reply #13 on: December 26, 2008, 07:56:52 PM »
Hi,

Thank you for your responses. I finally found the solution with the wrappermodule. The white border around the site was caused by the "blank" template wich can easily be modified by changing the backgroundcolor of the body. I don't know why I did not think about that earlier........

@Ruud
I'm not a programmer. Yet.....

@Erpe
Altough the problem is solved I'm still interested in that other solution so when you find it back I would appreciate it if you can post it here

Thank you all.  :-)

Regards,

Gerard

chross

  • Guest
Re: Getting content from a page or making global blocks 2...
« Reply #14 on: May 12, 2009, 02:12:27 PM »
I'm glad I found this solution here. Global content blocks is definitely something worth implementing for even better usability but not as high priority, of course.


Because my provider doesn't allow URL include, I am using the curl method as follows.

I added the following into the head section of my template:

<?php //--------PHP Blocks Script------------
function display_snippet($snippet){$ch = curl_init();$timeout = 5;curl_setopt ($ch, CURLOPT_URL, WB_URL.'/pages/snippet/'.$snippet.'.php');curl_setopt ($ch, CURLOPT_RETURNTRANS FER, 1);curl_setopt ($ch, CURLOPT_CONNECTTIME OUT, $timeout);$file_contents = curl_exec($ch);curl_close($ch);echo $file_contents;}
?>

In my pages I call the different blocks with load_snippet(testcontent);

Works perfectly fine for me.

Cheers
« Last Edit: September 02, 2010, 01:15:33 AM by chross »

 

postern-length