View Full Version : Show latest articles outside the script root
This came up as frequent request, so here is an example how to show latest articles outside the script's root. Let's say you installed phpWordPress in http://www.example.com/news directory, and you want to pull latest articles on your home page http://www.example.com
Place this code snippet anywhere in index file where you want the articles to appear:
<?php
include_once("<PATH_TO_SCRIPT>/include/conf.php");
include_once("<PATH_TO_SCRIPT>/include/db_conn.php");
function short_text($text)
{
$text=strip_tags($text);
$words=explode(' ',$text);
$word_number=50;
for ($i = 0; $i < $word_number; $i++) {
$short_text .= $words[$i]. " "; }
if ($i<sizeof($words)) $short_text .="...";
return $short_text;
}
function HTML_show_friendly_url($id)
{
if ($showFriendlyURL<>"no") {
$query="Select * from tblArticles where id=$id";
$result=mysql_query($query) or die("bad query friendly aricles");
$row=mysql_fetch_array($result);
if ($row['SEfriendly']<>"")
$idf=$row['SEfriendly'];
else
$idf=$row['id'];
if (!$rule=friendly_path($row['category_id']))
$rule="news/";
$frURL=$rule.$idf.".html";
} else {
$frURL="index.php?".$rule."=".$id;
}
return $frURL;
}
function friendly_path($cat_id)
{
$cat_list=array();
$end=0;
while (!$end)
{
$query="SELECT * from tblCategories where id=$cat_id";
$result=mysql_query($query) or die ("Bad query Article_Breadcrumb");
if ($row=mysql_fetch_array($result))
{
$name=$row['category_name'];
$category=array('id'=>$cat_id,'name'=>$name);
array_push($cat_list, $category);
$cat_id=$row['parent_cat'];
if ($cat_id==0) $end=1;
}
}
$friendly_path="";
$cat_list=array_reverse($cat_list);
foreach($cat_list as $ct)
{
if ($ct['name']==htmlentities($ct['name']))
$friendly_path.=urldecode($ct['name'])."/";
else return false;
}
return $friendly_path;
}
$query="SELECT * FROM tblArticles WHERE status=1 ORDER BY created DESC LIMIT 5";
$result=mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($result))
{
echo '<a href="'.$url.HTML_show_friendly_url($row['id']).'" >'.$row['title'].'</a>\r\n';
echo "<br />\r\n";
echo short_text($row['body']);
}
?>
Note: choose correct path to "include" folders, and customize display via CSS the way you want.
This displays 5 latest articles, using Friendly_URL support. If you want to modify munber of articles, just amend the query (SQL SELECT statement), and instead of LIMIT 5, put desired number.
mathu300
01-16-2006, 03:37 AM
if i ad this in root than how to please , because i plan to ad some Articles from "category_id" at front page so
how can i do this
please ..........
boccio
01-16-2006, 06:50 PM
function short_text($text)
{
$text=strip_tags($text);
$words=explode(' ',$text);
$word_number=50;
for ($i = 0; $i < $word_number; $i++) {
$short_text .= $words[$i]. " "; }
if ($i<sizeof($words)) $short_text .="...";
return $short_text;
}
function HTML_Box_Most_Popular11()
{
global $url, $tpl_folder, $lang, $cur_date;
$sql = "SELECT * FROM tblArticles WHERE category_id =13 ORDER BY created DESC LIMIT 4";
$result=mysql_query($sql) or die ("Bad query show most <br/>".$sql);
while ($row=mysql_fetch_array($result)) {
$id=HTML_show_friendly_url($row['id'],"");
$most_reading_articles.="<tr><td class=\"plainTxt2\"><img src=\"{$url}images/arrow5.gif\" align=absmiddle\" /> <a href=\"{$url}{$id}\">{$row['title']}</a></td></tr>"; //";
$most_reading_articles.= short_text($row['body']);
}
$filename="$tpl_folder/box_cat11.tpl";
$subject=file_get_contents($filename);
$pattern=array(
'/{ROOT}/',
'/{MOST_headline_news11}/',
);
$replacement=array(
$url,
$most_reading_articles,
);
$subject=preg_replace($pattern, $replacement, $subject);
return $subject;
}
this is roughly how it should work. you got headlines right, but to show body text as well, you need to invoke $row['body']. function short_text() merely strips first n words (in this case 50).
andy77
04-18-2006, 10:35 AM
I suppose it would be a nice feature to make some JavaScript code to include in home page of the site (outside the phpWordPress). Just like vBulletin does, or few others... Much easier then PHP code.
Just a thought...
BoogieDownBronx
09-13-2006, 09:33 PM
I suppose it would be a nice feature to make some JavaScript code to include in home page of the site (outside the phpWordPress). Just like vBulletin does, or few others... Much easier then PHP code.
Just a thought...
Something to keep in mind for those wanting to get things spidered...
Javascript routines that pull up nice information for an end user DO NOT get pulled up (executed) by search engine spiders.
I always vote for flexiblility, but search engine spidering is a MUST for me.
Troy
cocota
10-13-2006, 09:05 PM
Hello,
Your patch work very well, but i would love add the date of each news just before the news title, it's possible....?
Thanrks
Regards
Cocota
cocota
10-13-2006, 10:23 PM
i find that for my problem, i have add this code just after :
return $friendly_path;
}
}
function Show_Date()
{
global $article,$show_date;
if (($show_date=='Yes') and ($article->Created!=''))
{
$time=date("M d,Y");
$subject=$time;
}
return $subject;
}
$query="SELECT * FROM tblArticles WHERE status=1 ORDER BY created DESC LIMIT 5";
$result=mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($result))
{
echo '<div class="plainTxt">'.$row['created'].' :: <a href="'.$url.HTML_show_friendly_url($row['id']).'">'.$row['title'].'</a></div>';
echo short_text($row['body']);
echo "<br /><br />";
}
?>
So now is ok ,date of article appear before the latest 5 article title
(sorry for my bad english i'm a french webmaster)
but again a little problem
on the result i have the hours, always at 00:00:00
I don't know if my code is good i'm not a php specialist,and not find where correct that.
How delete this hour and keep only date.
You can see a result here (is a page test):
www.casinovirtuel.net/essai.php
Other little problem,
why when i clic on one link title my url is good but i get that:
casino-poker-bingo/News%20Casinos%20en%20ligne/Bonus%20sans%20Depot%20Casinos/cameo-casino-10-gratuit.html
instead that
casino-poker-bingo/News-Casinos-en-ligne/Bonus-sans-Depot-Casinos/cameo-casino-10-gratuit.html
Thanks
Cocota
gyllingdk
10-18-2006, 04:37 AM
Hi alex
I get this thread recommended from support staff, and we have tried it, but it doesnt seem to work at all.
Our Vivvo is placed in a subdomain, and NOT a subfolder in pageroot, eg.
http://articles.domain.com
What we need is to show EXACTLY the same as in the centerblock at our Vivvo frontpage, in a centerrblock at our mainpage. This block should automatically update whenever our editors/authors post a new article.
We have been experimenting with the path in the example you gave above, but NOTHING works. Our server is running at a Plesk, and I dunno if that might be the reason tat we cant connect to the database (at least this is the err msg we get when trying)
Is there any way to bypass this and get content loaded into our mainpage from vivvo?
Hope some of you would be able to help
Thanks
/Hans
cocota
10-22-2006, 11:05 AM
hello,
Your support on this forum is terrific....
never get an answer.....if you buy this script you must be a php pro !!!!
Never support on this forum, your script is expensive and no support,
Fantastic !!!!!
This patch not work so perhaps a little help ????
Not possible ???? to get some answer ???? for my url problem.....
Thanks
I took a glance at your site, and apparently you made a lot of modifications to PHP yourself... the URL is quite corrupted, it shouldn't be like that at all.
http://www.casinovirtuel.net/news-casino-poker/News%20Casinos%20en%20ligne/News-Casinos-en-ligne/Bonus%20sans%20Depot%20Casinos/Bonus-sans-Depot-Casinos/rubyfortune-casino-freetime-bonus.html
This isn't the URL that Vivvo normally generates...
We can't offer you support for something you messed with yourself, thus only by looking at your site via browser.
If you have problems with Vivvo, normal support channel is via HelpDesk, the Forum is community place, not the official support channel.
cocota
10-22-2006, 01:18 PM
gyllingdk, you can test this part of code, make several modification (because the first code not work) and NOW, work perfetly for me....
My config(adapt for your site)
directory script install= news-casino-poker
Latest news appear on my index root page without a problem
Red= code to add or remplace
only one problem article display :
2006-10-20 00:00:00 :.....short article display.... hours is always 0, not find the problem.....
<?php
include_once("/home/httpd/vhosts/www.casinovirtuel.net/web/news-casino-poker/include/conf.php");
include_once("/home/httpd/vhosts/www.casinovirtuel.net/web/news-casino-poker/include/db_conn.php");
function short_text($text)
{
$text=strip_tags($text);
$words=explode(' ',$text);
$word_number=30;
for ($i = 0; $i < $word_number; $i++) {
$short_text .= $words[$i]. " "; }
if ($i<sizeof($words)) $short_text .="...";
return $short_text;
}
function HTML_show_friendly_url($id)
{
if ($showFriendlyURL<>"no") {
$query="Select * from tblArticles where id=$id";
$result=mysql_query($query) or die("bad query friendly aricles");
$row=mysql_fetch_array($result);
if ($row['SEfriendly']<>"")
$idf=$row['SEfriendly'];
else
$idf=$row['id'];
if (!$rule=friendly_path($row['category_id']))
$rule="news-casino-poker/";
$frURL=$rule.$idf.".html";
} else {
$frURL="index.php?".$rule."=".$id;
}
return $frURL;
}
function friendly_path($cat_id)
{
$cat_list=array();
$end=0;
while (!$end)
{
$query="SELECT * from tblCategories where id=$cat_id";
$result=mysql_query($query) or die ("Bad query Article_Breadcrumb");
if ($row=mysql_fetch_array($result))
{
$name=$row['category_name'];
$category=array('id'=>$cat_id,'name'=>$name);
array_push($cat_list, $category);
$cat_id=$row['parent_cat'];
if ($cat_id==0) $end=1;
}
}
$friendly_path="";
$cat_list=array_reverse($cat_list);
foreach($cat_list as $ct)
{
$ct['name'] = str_replace(' ', '-', $ct['name']);
// if ($ct['name']==htmlentities($ct['name']) && !strpos($ct['name'],'/'))
if ($ct['name'] == preg_replace('/[^a-zA-Z0-9\_\-]/', '', $ct['name']))
$friendly_path.= urldecode($ct['name'])."/";
else return false;
}
return $friendly_path;
}function Show_Date()
{
global $article,$show_date;
if (($show_date=='Yes') and ($article->Created!=''))
{
$time=date("M d,Y");
$subject=$time;
}
return $subject;}
$query="SELECT * FROM tblArticles WHERE status=1 Order by order_num desc limit 4";
$result=mysql_query($query) or die(mysql_error());
while ($row=mysql_fetch_array($result))
{
echo '<div class="plainTxt"><b>'.$row['created'].' :: <a href="'.$url.HTML_show_friendly_url($row['id']).'">'.$row['title'].'</b></a></div>';
echo short_text($row['body']);
echo "<br /><br />";
}
?></p>
Don't know if my code is clean, not a php specialist, but it work....
peppesbodega
10-29-2006, 08:00 AM
Hi & thanks boccio !
I hade...and have the same problem as gyllingdk.
I works and gets the articles up on the homepage, BUT we are both on Windows servers and our Friendly_URL does not work.
My homepage is not on a different domain but in the folder ABOVE Vivvo.
Which means that if you click on the article headline you will arrive at a page that does NOT excist.
Do you know if there is a way to get the Articles without the Friendly_URL option ????
kamalrun
10-29-2006, 09:53 PM
hello
i was try this code work nice but it not showing image
i mean, when i pull Article its not showing image
kamalrun
function short_text($text)
{
$text=strip_tags($text);
$words=explode(' ',$text);
$word_number=50;
for ($i = 0; $i < $word_number; $i++) {
$short_text .= $words[$i]. " "; }
if ($i<sizeof($words)) $short_text .="...";
return $short_text;
}
function HTML_Box_Most_Popular11()
{
global $url, $tpl_folder, $lang, $cur_date;
$sql = "SELECT * FROM tblArticles WHERE category_id =13 ORDER BY created DESC LIMIT 4";
$result=mysql_query($sql) or die ("Bad query show most <br/>".$sql);
while ($row=mysql_fetch_array($result)) {
$id=HTML_show_friendly_url($row['id'],"");
$most_reading_articles.="<tr><td class=\"plainTxt2\"><img src=\"{$url}images/arrow5.gif\" align=absmiddle\" /> <a href=\"{$url}{$id}\">{$row['title']}</a></td></tr>"; //";
$most_reading_articles.= short_text($row['body']);
}
$filename="$tpl_folder/box_cat11.tpl";
$subject=file_get_contents($filename);
$pattern=array(
'/{ROOT}/',
'/{MOST_headline_news11}/',
);
$replacement=array(
$url,
$most_reading_articles,
);
$subject=preg_replace($pattern, $replacement, $subject);
return $subject;
}
shketuljko
11-01-2006, 11:09 AM
Cocota,
if you want keep only date you need replace this code:
echo '<div class="plainTxt">'.$row['created'].' :: :: <a href="'.$url.HTML_show_friendly_url($row['id']).'">'.$row['title'].'</a></div>';
with
echo '<div class="plainTxt">'.substr('$row['created']', 0, 10).' :: :: <a href="'.$url.HTML_show_friendly_url($row['id']).'">'.$row['title'].'</a></div>';
shketuljko
11-01-2006, 11:26 AM
kamalrun,
if you want to see image of this article you need replace this code:
$most_reading_articles.="<tr><td class=\"plainTxt2\"><img src=\"{$url}images/arrow5.gif\" align=absmiddle\" /> <a href=\"{$url}{$id}\">{$row['title']}</a></td></tr>"; //";
with:
$most_reading_articles.="<tr><td class=\"plainTxt2\"><img src=\"{$url}files/".{$row['image']}."\" align=absmiddle\" /> <a href=\"{$url}{$id}\">{$row['title']}</a></td></tr>"; //";
superman
11-30-2006, 12:20 AM
is there a simplar way to do it? I don't it in the .php file I have a tpl file that I am trying to make the articlesdesplay on.
superman
12-02-2006, 08:16 PM
can youguys add the javascript code also...
so far I am gettign this error
"".$sql); while ($row=mysql_fetch_array($result)) { $id=HTML_show_friendly_url($row['id'],""); $most_reading_articles.="
{$row['title']}
"
Frankc
04-01-2007, 07:25 PM
I tried this for some hours but later gave up and did something else.
I simply create a short script to connect to database (can connect server wide) and then pull the data direct from the database with this.
<?
include("conf.php");
?>
<?
$queryupdate = "select * from tblArticles where category_id = '106'";
$resultupdate = MYSQL_QUERY($queryupdate);
$numberupdate = mysql_Numrows($resultupdate);
if ($numberupdate>0) {
$x=0;
?>
<?
while ($x<$numberupdate)
{
?>
<font color="#FF00FF"><b><? $title=mysql_result($resultupdate,$x,"title"); ?> <? echo $title; ?></b></font><br> <br>
<? $image=mysql_result($resultupdate,$x,"image"); ?>
<?
if ($image == ""){
$image = "spacer.gif";
}
else
?>
<img src="../files/<? echo $image; ?>" align="left" border="0" hspace="8" vspace="8" style="padding-right: 10px;" />
<? $body=mysql_result($resultupdate,$x,"body"); ?> <? echo $body; ?>
<?
$x++;
} // end while
} // end if
?>
apocan
04-03-2007, 08:46 PM
Hi & thanks boccio !
I hade...and have the same problem as gyllingdk.
I works and gets the articles up on the homepage, BUT we are both on Windows servers and our Friendly_URL does not work.
My homepage is not on a different domain but in the folder ABOVE Vivvo.
Which means that if you click on the article headline you will arrive at a page that does NOT excist.
Do you know if there is a way to get the Articles without the Friendly_URL option ????
this message was sent before but maybe anyone needs this help.by changing "friendly" into "no" in the conf file, you can use it without seo friendly mod.but there will be problem using the categories at this time... it will give 404 error when you click on this
sithaaraa
05-09-2007, 07:12 AM
hey guys
i am try a lot but its not work and faced php error
here is that error
Warning: main(/public_html/beta/include/conf.php) [function.main]: failed to open stream: No such file or directory in /home/vaikara/public_html/vv.php on line 3
Warning: main() [function.include]: Failed opening '/public_html/beta/include/conf.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/vaikara/public_html/vv.php on line 3
Warning: main(/public_html/beta/include/db_conn.php) [function.main]: failed to open stream: No such file or directory in /home/vaikara/public_html/vv.php on line 4
Warning: main() [function.include]: Failed opening '/public_html/beta/include/db_conn.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/vaikara/public_html/vv.php on line 4
Warning: mysql_query() [function.mysql-query]: Access denied for user 'vaikara'@'localhost' (using password: NO) in /home/vaikara/public_html/vv.php on line 67
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/vaikara/public_html/vv.php on line 67
Access denied for user 'vaikara'@'localhost' (using password: NO)
________
Homemade Vaporizer (http://homemadevaporizers.info/)
sithaaraa
05-10-2007, 09:59 AM
it work nicely but there is a problem in url..
i want gererate url like below
www.domain.com/index.php?news=22
is it possible ...?
________
Prilosec Attorneys (http://www.classactionsettlements.org/lawsuit/prilosec/)
sithaaraa
06-08-2007, 07:38 AM
I tried this for some hours but later gave up and did something else.
I simply create a short script to connect to database (can connect server wide) and then pull the data direct from the database with this.
<?
include("conf.php");
?>
<?
$queryupdate = "select * from tblArticles where category_id = '106'";
$resultupdate = MYSQL_QUERY($queryupdate);
$numberupdate = mysql_Numrows($resultupdate);
if ($numberupdate>0) {
$x=0;
?>
<?
while ($x<$numberupdate)
{
?>
<font color="#FF00FF"><b><? $title=mysql_result($resultupdate,$x,"title"); ?> <? echo $title; ?></b></font><br> <br>
<? $image=mysql_result($resultupdate,$x,"image"); ?>
<?
if ($image == ""){
$image = "spacer.gif";
}
else
?>
<img src="../files/<? echo $image; ?>" align="left" border="0" hspace="8" vspace="8" style="padding-right: 10px;" />
<? $body=mysql_result($resultupdate,$x,"body"); ?> <? echo $body; ?>
<?
$x++;
} // end while
} // end if
?>
nice it's work anyway i want add link to title how?
________
Kitchen Measures (http://kitchenmeasures.com/)
goowoi
08-27-2007, 04:24 PM
hi
i need, how pull Article and showing image
plzz
gyllingdk, you can test this part of code, make several modification (because the first code not work) and NOW, work perfetly for me....
My config(adapt for your site)
directory script install= news-casino-poker
Latest news appear on my index root page without a problem
Red= code to add or remplace
only one problem article display :
2006-10-20 00:00:00 :.....short article display.... hours is always 0, not find the problem.....
Don't know if my code is clean, not a php specialist, but it work....
celticangel
10-09-2007, 06:04 PM
Hi,
the script you show above is working fine but I want to amend it to include the author name and to show only articles from a specific category. Can you help?
Thanks,
stargundem
10-24-2007, 07:51 AM
v4 ? :confused:
utvara
10-24-2007, 01:32 PM
For v4 please refer to http://www.vivvo.net/forums/showthread.php?t=1380
stargundem
10-28-2007, 08:41 PM
hi! i'm a problem. the end time newscat code for v4. v3.5 upgrade code v4. Thnx
stargundem
10-29-2007, 02:18 PM
:confused:
Micha
10-30-2007, 09:42 AM
hi! i'm a problem. the end time newscat code for v4. v3.5 upgrade code v4. Thnx
I'm not sure i understand you, can you please be more specific about this?
Opera
11-23-2007, 06:56 PM
well as i was working on making the last news go out and appear on the home page of my site, i found that i have some problems in styling it, so how could i style it, and make it appear as it is generated and appear in the system folder???
many thanks for your help
apocan
12-23-2007, 07:42 PM
advertisements :)
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.