{SHOW_CONTENT} Show content of a particular content part

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

{SHOW_CONTENT} Show content of a particular content part

Post by JensZ »

Hello,

Another replacement tag to show the contents of a particular content part. Can be very useful. It hasn't been tested for all content parts, but should work for most of them.

Put the following in a php file (for example show_content.php) in frontend_render.

Code: Select all

<?php
//----------------------------------------------------------------------------------------------
// {SHOW_CONTENT}
// AUTHOR: 			Jens Zetterström 
// DESCRIPTION: 	Shows the content of the article content part with the specified id. 
// INSTALLATION: 	Put the code in frontend_render (for example in a file called show_content.php)
//						Note: If the article content part contains replacement tags (for example {SITE}),
//						they will not be replaced because code in frontend_render is executed after those 
//						replacement tags already have been processed. To fix, put the code in 
//						content.article.inc.php instead.
// USAGE: 			{SHOW_CONTENT:acontent_id}
//						where acontent_id is the id of the content part.
//----------------------------------------------------------------------------------------------
function show_content($id, $db)
{
	$CNT_TMP = '';
	$template_default = $GLOBALS["template_default"];
	
	$sql =	"SELECT * " .  
				"FROM " . DB_PREPEND . "phpwcms_articlecontent " .
				"INNER JOIN " . DB_PREPEND . "phpwcms_article ON " . DB_PREPEND . "phpwcms_article.article_id = " . DB_PREPEND . "phpwcms_articlecontent.acontent_aid " .
				"WHERE acontent_id = " . $id . " " .
				"AND acontent_visible = 1 " . 
				"AND acontent_trash = 0 " .
				"AND " . DB_PREPEND . "phpwcms_article.article_deleted=0 AND ".DB_PREPEND."phpwcms_article.article_begin < NOW() " . 
				"AND " . DB_PREPEND . "phpwcms_article.article_end > NOW() ";
				"ORDER BY acontent_sorting, acontent_id;";
				  
	if($cresult = mysql_query($sql, $db) or die("error retrieving article from database")) 
	{
		if($crow = mysql_fetch_array($cresult)) 
		{
			// Space before
			if($crow["acontent_before"]) 
			{
				$CNT_TMP .= '<div style="margin:' . $crow["acontent_before"] . 'px 0 0 0; padding:0 0 0 0; clear:both;"></div>';
			}
			
			// include content part code section
			include("include/inc_front/content/cnt" . $crow["acontent_type"] . ".article.inc.php");

			//check if top link should be shown
			if($crow["acontent_top"]) 
			{
				if($template_default["article"]["top_sign_before"].$template_default["article"]["top_sign_after"]) 
				{
					$CNT_TMP .= $template_default["article"]["top_sign_before"];
					$CNT_TMP .= '<a href="#top">'.$template_default["article"]["top_sign"].'</a>';
					$CNT_TMP .= $template_default["article"]["top_sign_after"];
				} 
				else 
				{
					$CNT_TMP .= '<br /><a href="#top">' . $template_default["article"]["top_sign"] . '</a>';
				}
			}

			// Space after
			if($crow["acontent_after"]) 
			{
				$CNT_TMP .= '<div style="margin:0 0 ' . $crow["acontent_before"] . 'px 0; padding:0 0 0 0; clear:both;"></div>';
			}
		}
	}
	return $CNT_TMP;
} 

if( ! ( strpos($content["all"],'{SHOW_CONTENT:')===false ) )
{
	$content["all"] = preg_replace('/\{SHOW_CONTENT:(.*?)\}/ie', 'show_content("$1", $db);', $content["all"]);
}


?>
Cheers,

Jens
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Nice one Jens!

Got a question....and this one might be stupid.....it is somewhat unrelated to this great rep tag....

is there anyway to access the article_id within a given article. I am working on a modification to a shopping cart script where I simply want to allow the administrator to type in {PRICE:24.00} within the article itself......and have the backend take this data and insert into an additonal table phpwcms_pricetable. Up to now I have gotten this to work:

{PRICE:7:24.00}

where 7 equals the article_id.....seems silly to have to manually enter the article_id..

and wanted to ask if the article_id can be implicitly called, thus eliminating the need to manually enter it....I have to think this is simple and it is something I am overlooking.

:D
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

Post by JensZ »

Hi jsw_nz,

Sure, the current article id is stored in a global variable:

Code: Select all

$GLOBALS["content"]["article_id"]
Hope that helps!

Jens
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Thanks JensZ,

Apparently I had the expression wrong....was using:
$GLOBALS['content']['articles']['article_id']

Should have been using:
$GLOBALS["content"]["article_id"]

as you mentioned.
Now works like a charm :D :D
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

--...--/index.php/topic,152.0.html

:-)
iceman
Posts: 82
Joined: Tue 13. Jul 2004, 09:44
Contact:

Post by iceman »

Looks and sounds very nice!

Can you give a description of how you (or others) have used this in real examples?

ie: just trying to get an idea of how I could use this..
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

Come to think of it, seeing this in action would be a good idea...
TriP
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

This is a gem of a replacement tag!

In principal you could create a separate editable section of 'content parts' in a site category (hidden) that would be displayed using custom blocks (right, left,etc) embedded in page templates Would allow the client to have one place to edit content that shows up in various parts of site AND in various places on page (right sidebar, left sidebar, etc).

This is a must have for the core of Wcms.
:D :D

Oliver...I hope you read this.....all the best!
rtilghman
Posts: 107
Joined: Tue 1. Mar 2005, 17:22

Post by rtilghman »

This is indeed a cool mod. A couple quick questions:

1. Can this be made into a more formal RT using the provided format so you don't have to edit core files?

2. Isn't there new functionality like this in the latest dev release? I seem to remember reading about something similar in 2.5, but I may be wrong.

3. Is there a reason not to just put the provided code into "content.article.inc.php"? I mean, it seems like copying it into frontend_render kills your ability to have RTs in content get processed (meaning any content you try to include that HAS RTs will have the code instead of content). If therte isn't a downside maybe make content.article the default?

Best,
Rick
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

Hi rtilghman,

Good questions...I would guess that the code as is could be placed in content.func.inc.php and then be a standard Wcms rep_tag. Obviously the fact that it already works in frontend_render would suggest that this is not all that important, at least from OliG's point of view. I would say there are situations where placing code in content.func.inc.php is better. I had a situation where I wanted to use the {PAGETITLE} tag combined with Jerome's GT mod. The code was:

Code: Select all

{GT:myStyle}{PAGETITLE}{/GT}
So like you alluded to, the operation of nested rep tags is affected by where they are placed and the order in which they are executed. In the above code, having the {PAGETITLE} tag in frontend_render did not work. GT would spit out {PAGETITLE}. Only by putting the code in content.func.inc.php (and before tcall to GT mod) did it first get parsed and properly rendered by GT mod.

With regards to second ?, the newest dev release sports 'contentpart alias', something similar in scope, but not recommended for page templates. A couple of threads can be read here:

http://www.phpwcms.de/forum/viewtopic.php?t=8233

All best,
:D

link to {PAGETITLE} code:
--...--/index.php/topic,86.0.html
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

Post by JensZ »

Hey jsw_nz!

I'm glad the repl tag was appreciated by others. Check out http://www.phpwcms.de/forum/viewtopic.php?t=8521 for my news flash content part that will take article flexibility even further, at least for me...

Regards,

JZ
User avatar
anthony.abraira
Posts: 99
Joined: Sun 11. Sep 2005, 07:42
Location: Mars Hill, NC
Contact:

The files all end with _ (i.e. sample.php_)

Post by anthony.abraira »

Hey I just tried getting this replacement tag installed and came across two problems. First the frontend render was actually mislabled.. like this:

SITE/phpwcms_template/inc_script/inc_script/

I changed it to:

SITE/phpwcms_template/inc_script/frontend_render/

The files listed were:
  • isNew.php_
    menbar.php_
    sample.php_
    sublevelnav.php_
I went ahead and checked another domain that was running WCMS and it seems that this was just a fluke accident. If otherwise please let me know. Anyway, so I put the show_content.php file. Do I need to put the underscore on the file:

show_content.php_

:?: [/list]
JensZ
Posts: 136
Joined: Wed 16. Feb 2005, 12:18
Location: Stockholm, Sweden
Contact:

Post by JensZ »

The underscore prevents the script from being loaded and executed. So all scripts you want to use should have .php extension (without underscore).
macmukka

content.func.inc.php

Post by macmukka »

I've been trying to use {SHOW_CONTENT} with the GT MOD:-

{GT} {SHOW_CONTENT: id} {/GT}

At first it wouldn't work only producing an image with {SHOW_CONTENT:id}.

But I put the {SHOW_CONTENT} code above the GT code in content.func.inc.php and now it works.

BUT it adds DIVS to the beginning and the end of the image.

I AM just a beginner and so have played with the code but cannot remove the DIVs- can someone help? Thanks -
User avatar
update
Moderator
Posts: 6455
Joined: Mon 10. Jan 2005, 17:29
Location: germany / outdoor

Post by update »

Hi all,
I haven't been here for a while, but still playing with phpwcms and getting more and more fond of it (working at my very first site with phpwcms :oops: .

My question: How can this script here be changed to put out random articles (or content parts) of a choosen structure?
I tried but noway since I'm no php'ist

Greetings
Claus
Post Reply