Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
display page excerpt - plugin
#1
I've finally accomplished creating a plugin to grab declared's page excerpt, and show its content on another page.

Syntax:
All you have to do is to launch the plugin inside your template, or inside a component box (which is more comfortable) along with 1 or 2 arguments.
1st argument is a name of the page (its file/URL) whose content you want to load (don't forget about commas)
2nd argument is the amount of chars you want to display. Default amount is 200, thus if you don't set the value it will just show 200 first chars.

Example of showing 60 first chars from index page:
Code:
<?php show_page_excerpt("index",60) ?>


Error handling:
if you use a non existing page, you will be notified about that.


additional notes:
- If page's content will be shorter than amount of text you want to display, a "read more" link to page won't be displayed.

- this plugin stripes whole html tags along with images, thus it shows only plain text




ps. this is my first attempt to create a plugin. I think it works great, and can be a nice addon to a webpage. I used it on www.tkaczjanik.pl website, to display 2 excerpts of pages placing them inside boxes on the right side.

Let me know if you find a bug, as I won't publish it on GS website until I am sure it won't blow out user's GS instance Wink
Addons: blue business theme, Online Visitors, Notepad
Reply
#2
yojoe, pls could you reexplain a little bit more about installation & configuration?

1. Upload page-excerpt.php to the plugins folder, right?
2. Place this code <?php show_page_excerpt("index",60) ?> in the template page template.php ?
Reply
#3
1. Yes, you have to upload it into plugins directory, and if it is recognized correctly, you should see plugin's description in plugins tab.

2. Yes, you can call the plugin from within template, or use component box (paste component box display code into template, and paste excerpt's plugin call into the component box window from within GS administration panel)
The code you used will show 60 first plain chars from index page.
Addons: blue business theme, Online Visitors, Notepad
Reply
#4
Yes, a wonderful and simple plugin, it works
http://neowebtime.ru/0/index1
Is it possible to do so, to be displayed and the page title?
Reply
#5
Oleg06 Wrote:Yes, a wonderful and simple plugin, it works
http://neowebtime.ru/0/index1
Is it possible to do so, to be displayed and the page title?

Generally it's possible to strip whole content blocks from xml file, for example:
<pubDate>, <title>, <parent> etc.

The question is: what data blocks could be useful, and how should they be displayed ?
I tried to use simplest syntax as possible, although I'm not skilled enough to create a nice trigger, to show page excerpts by invoking the plugin inside page edit field (like for example P01's contact plugin).

But should I add an additional argument when calling function or just make 1 argument to show all defined content (title, date, excerpt content) ?
One argument is not a problem, but 2 or more would complicate the purpose of this simple plugin pretty much. If a user place arguments in a wrong sequence, this will make him angry when the plug won't work :]


Other thing is styling grabbed content.
I could embed it inside <div>,<span> or in <p> and assign them an ID, so user could stylize those blocks content from within his own .css file. But in current version user can embed grabbed content wherever he wants and stylize it in his own will.
Addons: blue business theme, Online Visitors, Notepad
Reply
#6
Hi,

I have quickly worked on it : partly rewritten, commented, and some following things added/changed.

[h]Function call :[/h]

Main function had to be printed :
Code:
<?php echo page_excerpt('name'); ?>
You can always define excerpt length (60 by default):
Code:
<?php echo page_excerpt('name', 60); ?>
You can also defining the output type (text or html, text by default) :
Code:
<?php echo page_excerpt('name', 60, 'html'); ?>


[h]Page parsing :[/h]

A page excerpt can be called from page editor with tag :
Code:
(% excerpt : name %)
You can define excerpt length :
Code:
(% excerpt : name, 60 %)
And output type :
Code:
(% excerpt : name, 60, html %)

Wink

PS : i add that to GS extend.
Reply
#7
why, when I insert the html, it appears?
чт�
http://neowebtime.ru/0/index1
Reply
#8
The substr() function slice characters bytes, without looking a charset (UTF-8 use 3 bytes for a char). I just discovered mb_substr(), multi-bytes substr : http://php.net/manual/en/function.mb-substr.php

So replace line #72 by :
Code:
$excerpt = mb_substr($excerpt, 0, $chars, 'UTF-8');
Reply
#9
Thanks, it works
Reply
#10
p01: could you explain more about differences between mb_substr() and substr() ?
I was having some problems with stand alone contact form, and I had to get rid of mb_substr() function, as I had exactly opposite problem to Oleg's one.

Should mb_substr() function be used when it goes to chars encoded in utf-16/32 (like chineese or russian) and substr() for ascii or utf8 ?

I don't have much knowledge about this :\


edit: completely forgot to mention about changes you made. I'm glad you didn't at least delete whole credits xD
Addons: blue business theme, Online Visitors, Notepad
Reply
#11
Hi,

UTF-8 is a multi-bytes encoding (and variable-width encoding), using one (ASCII) to three (Hindi) bytes according to character nature. UTF-16 follow the same process but use more space for ASCII and less for non-ASCII.

substr() is a byte substraction function : when you set start and stop, you are not indicating characters but bytes. If the encoding use single bytes (like ASCII) it's the same thing, but if the encoding use multi-bytes (UTF-x, ISO-x...), you could cut a string in the middle of a character bytes, who become unreadable. To avoid this, you have to know the number of bytes used by every characters : it's the work of mb_substr().
mb_substr() is a multi-bytes (and variable-width) substraction function : when you set start and stop, you are indicating characters, according to a specific encoding. The function manage the number of bytes to skip according to every character bytes width.

To read :
http://en.wikipedia.org/wiki/UTF-8
http://en.wikipedia.org/wiki/UTF-8#Description
http://en.wikipedia.org/wiki/UTF-8#Disadvantages_2
http://en.wikipedia.org/wiki/Character_encoding
http://en.wikipedia.org/wiki/Variable-width_encoding
http://php.net/manual/en/ref.mbstring.php
http://php.net/manual/en/function.substr.php
http://php.net/manual/en/function.mb-substr.php

yojoe Wrote:edit: completely forgot to mention about changes you made. I'm glad you didn't at least delete whole credits xD
Oh, I hope not to have done something wrong! I worked on it after your request for help, and could not hold me to restructure the whole. The official author, indicated in the admin panel is still you :\
Reply
#12
Does this work fully on GS 2.03? I'm trying to modify this so I can display entire pages within pages and can't get the tag parsing to work, it's not replacing the tag:
Code:
(% excerpt : name %)
Calling page_excerpt from a template works fine, but I really need to be able to include them from the WYSIWYG editor.

Edit: Figured it out, it was a conflict with the Exec-PHP plugin which I didn't need anyway.
Reply
#13
may do so to remove the backslash from the code?
Code:
<img alt=\"\" src=\"http://chaga-mushroom.com/data/thumbs/thumbnail.1.jpg\" style=\"height: 93px; width: 70px; margin: 3px 5px; float: left;\" />
http://chaga-mushroom.com/yyyyyy/
Reply
#14
try to add:
$excerpt = stripslashes($excerpt);
after line 67.
Addons: blue business theme, Online Visitors, Notepad
Reply
#15
thanks, helped Smile
Reply
#16
Hi there,

is it possible that this plugin does not work with sub-pages?

I.e.:
Quote:echo page_excerpt('onepage/childpage', 60);

Can't get that to work.

Edit: sorry, just figured out I just need the page name itself. This does work:
Quote:echo page_excerpt('childpage', 60);
Reply
#17
i was wondering, is it possible to show the content till some kind of tag? E.g the plugin would stop showing the content till the tag (e.h '<more>') in the page content?
Reply
#18
Thanks yojoe and p01 for the plugin.


Now ... a noob question, im unsure about the meaning of "60 first chars:"
Is it Characters? It counts the letters and all?


Many thanks.
Reply
#19
yes
|--

Das deutschsprachige GetSimple-(Unter-)Forum:   http://get-simple.info/forums/forumdisplay.php?fid=18
Reply
#20
if you choose html option the results is still encircled with <p></p> tags which I think was initially meant for text. Therefore you can get <p><div></div></p> or some other funny syntax. For correct html use this line 76 should be changed to
Code:
return $excerpt;
and <p>s should go a few lines up where output is conditioned by text/html parameter - line 68 should be extended to
Code:
$excerpt = trim(strip_html_tags($excerpt));$excerpt = '<p>' . $excerpt . '</p>';
Reply
#21
Thank you, Can we integrate the titles of pages? i believe that the more useful.
Reply
#22
Is there a way to have the display page excerpt plugin display just a thumbnail and the page title?

While I'm at it, any way that thumbnail could be one assigned to the page and necessarily one of the 1st image on the page?

Thank you
Reply
#23
Would it be possible to merge this into the news manager?
Todo arde si le aplicas la chispa adecuada.
Reply
#24
Look my mod
http://get-simple.info/extend/plugin/pag...pts-2/773/
Reply
#25
Does p01 allow you to do this ? What is the license of this, making sure people are aware you cannot just post someone elses work as your own plugin.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply




Users browsing this thread: 1 Guest(s)