Angryboy
Member
Posts: 184
Joined: Sep 2010
|
Displaying HTML code on pages
I want to be able to display code such as:
Code:
<?php
/* Credit to ccagle8 for the original function; edited by Angryboy */
function get_author_username($blogusername) {
$file = GSDATAPAGESPATH . $blogusername .'.xml';
if (file_exists($file)) {
$p = getXML($file);
$authoruser = $p->authoruser;
echo $authoruser; }
}
?>
In this form for tutorials about GetSimple. But even when I encode the < and > entities, they are still executed, making the code unable to be viewed and breaking the web page. This even goes for showing other bracketed codes:
Code:
(% stuff in here %)
I've had to insert spaces between the < and > signs, but I've seen other sites display their code just fine. Is there something I'm doing wrong, or could this be a server problem?
Thanks to whoever provides a solution!
In the middle of migrating content from Spriting on a Whim (soaw.hostingsiteforfree.com) to LOKIDA (lokida.co.uk) - all my GetSimple tutorials will be hosted there.
|
|
|
|
mvlcek
Posting Freak
Posts: 1,739
Joined: Jan 2011
|
Displaying HTML code on pages
Angryboy wrote:I want to be able to display code such as:
Code:
<?php
function get_author_username($blogusername) {
...
?>
This works just fine for me in the page!?
Angryboy wrote:This even goes for showing other bracketed codes:
Code:
(% stuff in here %)
This is a real problem.
There is a workaround if you have htmlentities in ckeditor switched on (which is the default at least for GS 3.0): before saving the page go to source view and replace all % by %, then save immediately without switching to WYSIWYG mode.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
|
|
|
|
marrco
Member
Posts: 127
Joined: Dec 2009
|
Displaying HTML code on pages
mvlcek wrote:There is a workaround if you have htmlentities in ckeditor switched on (which is the default at least for GS 3.0): before saving the page go to source view and replace all % by %, then save immediately without switching to WYSIWYG mode.
i had a similiar problem last year and solved using a component for that code snippet
|
|
|
|
Angryboy
Member
Posts: 184
Joined: Sep 2010
|
Displaying HTML code on pages
mvlcek wrote:Angryboy wrote:I want to be able to display code such as:
Code:
<?php
function get_author_username($blogusername) {
...
?>
This works just fine for me in the page!?
Angryboy wrote:This even goes for showing other bracketed codes:
Code:
(% stuff in here %)
This is a real problem.
There is a workaround if you have htmlentities in ckeditor switched on (which is the default at least for GS 3.0): before saving the page go to source view and replace all % by %, then save immediately without switching to WYSIWYG mode.
I know it works fine for you, which is why I am a little jealous to be frank XD As you can see on the page link I gave, the code is still being processed as though the < and > were actual markers instead of entities. The HTML I view when I look at the CKEditor source on the page content tells me that they are entities, yet the page still processes them as non-entities. What is more annoying is that the code is displaying just fine from within the CKEditor!
@marcco: thanks for the contribution. Because I have a lot of code snippets in my tutorials however, it would be a bit cumbersome to produce a component for every code snippet I produced XD
In the middle of migrating content from Spriting on a Whim (soaw.hostingsiteforfree.com) to LOKIDA (lokida.co.uk) - all my GetSimple tutorials will be hosted there.
|
|
|
|
mvlcek
Posting Freak
Posts: 1,739
Joined: Jan 2011
|
Displaying HTML code on pages
Angryboy wrote:I know it works fine for you, which is why I am a little jealous to be frank XD As you can see on the page link I gave, the code is still being processed as though the < and > were actual markers instead of entities. The HTML I view when I look at the CKEditor source on the page content tells me that they are entities, yet the page still processes them as non-entities. What is more annoying is that the code is displaying just fine from within the CKEditor!
How do you format the code in CKEditor?
For me it only works, if I use the "Preformatted" entry in the standard "Format" combo box.
This way it's all within a <pre> (without <code> as for you).
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
|
|
|
|
eatons
Member
Posts: 59
Joined: Feb 2012
|
Displaying HTML code on pages
Angryboy wrote:I want to be able to display code such as:
Code:
<?php
/* Credit to ccagle8 for the original function; edited by Angryboy */
function get_author_username($blogusername) { ... }
?>
In this form for tutorials about GetSimple. But even when I encode the < and > entities, they are still executed, making the code unable to be viewed and breaking the web page. This even goes for showing other bracketed codes:
Code:
(% stuff in here %)
I've had to insert spaces between the < and > signs, but I've seen other sites display their code just fine. Is there something I'm doing wrong, or could this be a server problem?
Thanks to whoever provides a solution!
Have you tried pasting your code straight into the WYSIWYG editor?
Works for me!
http://eatons.net/tutorials/innnovationoutline/
InnovationOutline Theme Tutorial
|
|
|
|
Angryboy
Member
Posts: 184
Joined: Sep 2010
|
Displaying HTML code on pages
eatons wrote:Have you tried pasting your code straight into the WYSIWYG editor?
Works for me!
http://eatons.net/tutorials/innnovationoutline/
I've tried this now that you've asked. My source code in the WYSIWYG editor is this:
Code:
<pre>
<?php
/* Credit to ccagle8 for the original function; edited by Angryboy */
function get_author_username($blogusername) { ... }
?></pre>
When viewed on the actual page, the source code becomes this:
Code:
<pre> <!--?php
/* Credit to ccagle8 for the original function; edited by Angryboy */
function get_author_username($blogusername) { ... }
?--></pre>
Making it unviewable. Thanks for offering some help to me regardless :-)
In the middle of migrating content from Spriting on a Whim (soaw.hostingsiteforfree.com) to LOKIDA (lokida.co.uk) - all my GetSimple tutorials will be hosted there.
|
|
|
|
eatons
Member
Posts: 59
Joined: Feb 2012
|
Displaying HTML code on pages
Angryboy wrote:eatons wrote:Have you tried pasting your code straight into the WYSIWYG editor?
Works for me!
http://eatons.net/tutorials/innnovationoutline/
I've tried this now that you've asked. My source code in the WYSIWYG editor is this:
Code:
<pre>
<?php
...
?></pre>
When viewed on the actual page, the source code becomes this:
Code:
<pre> <!--?php
...
?--></pre>
Making it unviewable. Thanks for offering some help to me regardless :-)
I set up a test page at: http://eatons.net/tutorials/test/
Is either of these what you're looking for?
InnovationOutline Theme Tutorial
|
|
|
|
Angryboy
Member
Posts: 184
Joined: Sep 2010
|
Displaying HTML code on pages
eatons wrote:Angryboy wrote:eatons wrote:Have you tried pasting your code straight into the WYSIWYG editor?
Works for me!
http://eatons.net/tutorials/innnovationoutline/
I've tried this now that you've asked. My source code in the WYSIWYG editor is this:
Code:
<pre>
<?php
...
?></pre>
When viewed on the actual page, the source code becomes this:
Code:
<pre> <!--?php
...
?--></pre>
Making it unviewable. Thanks for offering some help to me regardless :-)
I set up a test page at: http://eatons.net/tutorials/test/
Is either of these what you're looking for?
The top one is
I think I've found the problem, and it might be a bug with the way that Special Pages processes page content. I copied the HTML code from your page onto a test normal page and it displays fine:
http://spritingonawhim.net.tc/testpage/
But that very same content on a special page:
http://spritingonawhim.net.tc/testpage2/
And it processes the <?php as thought it were an actual command. The use of
<?php get_page_content(); ?> in a Special Page's template doesn't output the content in the same way that it does for normal pages.
Thanks for your contribution, eatons!
--------------------
Found my solution!
Code:
<?php get_special_field('content', $default='', $isHTML=false); ?>
Instead of the usual get_page_content, because the default for that is to encode the characters < and > for special fields. Sorry for the trouble caused people!
Note for mvleck: you may want to make that clear on the Special Pages information you've got so that others don't make my silly mistake either!
In the middle of migrating content from Spriting on a Whim (soaw.hostingsiteforfree.com) to LOKIDA (lokida.co.uk) - all my GetSimple tutorials will be hosted there.
(This post was last modified: 2012-04-05 01:21:02 by logonsf.)
|
|
|
|