1 totof Jun 13, 2006 23:17
3 totof Jun 14, 2006 18:25
Thanks for your help, but the problem is that displays the last posts for 1 specific blog.
And I want to display the last posts for all blogs.
I've tried this :
<?php
include ('conf/config.inc.php');
$connexion = mysql_connect($host,$user,$password);
if ($connexion>0) echo "connexion effectuée <br />";
else die ('pas de connexion active');
mysql_select_db($name,$connexion);
$sql="SELECT * from evo_posts ORDER BY post_ID DESC LIMIT 5";
mysql_query($sql) or die('Erreur SQL !'.$sql.''.mysql_error());
$result=mysql_query($sql);
for ($Compteur=0 ; $Compteur<mysql_numrows($result) ; $Compteur++)
{
$post_title = mysql_result($result , $Compteur , "post_title");
$post_content = mysql_result($result , $Compteur , "post_content");
$post_content = substr($post_content,0,150);
if ((strlen($post_title) == 0) && (strlen($post_content) != 0)) $post_title="No title specified";
echo "<h3>$post_title</h3>$post_content<br /><br />";
}
mysql_close();
?>
That display what i want, but with this, I can't find how to add a link to each post
4 yabba Jun 14, 2006 18:29
Blog 1 (which is what I used) is a list of all posts on all blogs in date order, which is what you would appear to want?
To also output the post content then you just need to add $Item->content(); to the code I posted.
¥
5 totof Jun 14, 2006 19:15
Thanks a lot
6 totof Jun 15, 2006 01:41
It's me again :oops:
All works fine, but now, I want to display only a part of the post
When I use
$Item->content();
This display the entire post.
I tried this :
<?php
substr ($Item->content(), 0, 150);
?>
but the post is still entire displayed
Any idea to display only a part of the post ?
Thanks in advance
7 yabba Jun 15, 2006 10:04
Try :-
<?php
format_to_output( substr( $Item->content, 0, 150 ) );
?>
¥
8 totof Jun 15, 2006 17:38
This doesn't work :(
When I use your code, nothing is displayed for the content and if I use :
<?php
format_to_output( substr( $Item->content(), 0, 150 ) );
?>
(If I add () after content), all the post is displayed.
If you have another Idea .....
9 edb Jun 15, 2006 17:49
Try doing a get like this:
<?php
substr ($Item->get('content'), 0, 150);
?>
Or maybe like this:
<?php
format_to_output( substr( $Item->get('content'), 0, 150 ) );
?>
I'm sort of thinking the first will do but I'm also thinking thinking clearly leads to exposing my inability to clearly think.
10 totof Jun 15, 2006 23:50
This doesn't work too :(
Nothing is displayed with these 2 codes.
:'( :'( :'(
11 yabba Jun 16, 2006 00:38
*cough* I forgot the echo :P
<?php
echo format_to_output( substr( $Item->content, 0, 150 ) );
?>
¥
12 edb Jun 16, 2006 04:59
The thing I was thinking of is that Item->content echos and get('whatever') doesn't, so maybe echoing a get is the answer?
13 yabba Jun 16, 2006 09:19
$Item->content() echos the result, but $Item->content and $Item->get( 'content' ) don't, so either of them should do the job (once the echo is added)
¥
14 totof Jun 19, 2006 15:37
Hi,
I didn't find a solution in spite of your assistance, so I've done this :
<?php
require(dirname(__FILE__).'/evocore/_main.inc.php');
include ('conf/config.inc.php');
$connexion = mysql_connect($host,$user,$password);
if ($connexion>0) echo "";
else die ('pas de connexion active');
mysql_select_db($name,$connexion);
$sql="SELECT * from evo_posts ORDER BY post_ID DESC LIMIT 5";
mysql_query($sql) or die('Erreur SQL !'.$sql.''.mysql_error());
$result=mysql_query($sql);
$ItemList = & new ItemList( 1, '', '', '', '', '', '', '', 'DESC');
echo '<ul>';
$Compteur=0;
while( $Item = $ItemList->get_item() )
{
?>
<li class="feed">
<a href="<?php $Item->permalink() ?>" title="Lire l'article en entier"><?php $Item->title( '', '', false ); ?></a>
</li>
<?php
$post_title = mysql_result($result , $Compteur , "post_title");
if ((strlen($post_title) == 0) && (strlen($post_content) != 0)) {
$post_title="Sans titre";
echo "<a href=\"$post_urltitle\" title=\"lire l'article en entier\"><span class=\"feed\">$post_title</span></a><br />";
}
$post_content = mysql_result($result , $Compteur , "post_content");
$post_content = substr($post_content,0,150);
echo "<span class=\"feed\">$post_content ...<br /><br /></span>";
$Compteur ++;
}
mysql_close();
?>
It's not a very clean code, but it works.
Thanks again for your help
Regards,
Totof
15 yabba Jun 19, 2006 17:12
See if this works for you :-
<?php
require(dirname(__FILE__).'/evocore/_main.inc.php');
$ItemList = & new ItemList( 1, '', '', '', '', '', '', '', 'DESC');
echo '<ul>';
while( $Item = $ItemList->get_item() )
{
echo '<li class="feed">
<a href="';
$Item->permalink();
echo '" title="Lire l\'article en entier"><span class="feed">'
.( $Item->title ? format_to_output( $Item->title ) : 'Sans titre' )
.'</span></a><br />
<span class="feed">'
.format_to_output( substr( $Item->content, 0, 150 ) )."\n\r"
.'</span></li>'."\n\r";
}
echo '</ul>';
?>
¥
16 totof Jun 19, 2006 23:48
It works very well.
Thanks a lot
Totof
17 yabba Jun 20, 2006 08:55
No problem ;)
¥
18 mrigby Jun 20, 2006 16:01
¥åßßå wrote:
Try something like this :-
<?php require(dirname(__FILE__).'/evocore/_main.inc.php'); // Get the lastest posts $ItemList = & new ItemList( 1 ); echo '<ul>'; while( $Item = $ItemList->get_item() ) { ?> <li lang="<?php $Item->lang() ?>"> <?php $Item->issue_date() ?>: <a href="<?php $Item->permalink() ?>" title="<?php echo T_('Permanent link to full entry') ?>"><?php $Item->title( '', '', false ); ?></a> <span class="small">[<?php $Item->lang() ?>]</span> </li> <?php } ?> </ul>
¥
Would the code above that you posted be used instead of the code in the summary.php, or would the above code be added to the homepage to display the last blog posts?
And if the code above is what goes on the homepage, then which parts of the summary.php code do I need to modify to get it working? I cannot seem to get it going as of yet. Here is the summary.php code, and if you could mark the items I need to edit I would appreciate it. Or give me a direction :) I haven't figured out yet which code I need to customize to my site, which is probably the problem.
require(dirname(__FILE__).'/b2evolution/_main.php'); #this is the actual directory name that my blogs are in#
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
For some reason this is seeming more difficult that it probably is. Thanks again.
*edit*
Reduced post to relevant bits
19 yabba Jun 20, 2006 18:16
Based on your post, you need to change this line :-
require(dirname(__FILE__).'/b2evolution/evocore/_main.inc.php');
The code goes in your home page (which will need to be a php page) wherever you want the posts to be displayed.
¥
20 mrigby Jun 20, 2006 21:09
¥åßßå wrote:
Based on your post, you need to change this line :-
require(dirname(__FILE__).'/b2evolution/evocore/_main.inc.php');The code goes in your home page (which will need to be a php page) wherever you want the posts to be displayed.
¥
Yabba,
I sent you a PM. I just want to make sure I am calling the correct php page using the above code, and I am not sure what code to change in the summary.php file itself to have it show what I want. Hopefully you can help me.
21 yabba Jun 21, 2006 10:02
HI Mike,
Ok, a few things, firstly the code in this thread if for the 1.6(alpha) version of b2evolution although it can work with a few minor modifications. Second, your blogs are running on 0.9.1 so I would advise you to upgrade to [url=http://b2evolution.net/downloads/index.html]0.9.2(sparkle)[/url] before doing anything else.
Once you've done that you just need to put the following code into your website homepage (I'm assuming you want your posts to appear on the page where you currently have "item1" "item 2" etc).
<?php
require(dirname(__FILE__).'/b2evolution/b2evocore/_main.php');
// Get the lastest posts
$ItemList = & new ItemList( 1, '', '', '', '', '', array(), '', 'DESC', '', '', '', '', '', '', '', '', '', '3', 'posts' );
echo '<ul>';
while( $Item = $ItemList->get_item() )
{
?>
<li lang="<?php $Item->lang() ?>">
<?php $Item->issue_date() ?>:
<a href="<?php $Item->permalink() ?>" title="<?php echo T_('Permanent link to full entry') ?>"><?php $Item->title( '', '', false ); ?></a>
<span class="small">[<?php $Item->lang() ?>]</span><br />
<?php $Item->content(); ?>
</li>
<?php
}
?>
</ul>
Your homepage will need to be a php page, and you can change the 3 in this line to the number of posts you want to display :-
$ItemList = & new ItemList( 1, '', '', '', '', '', array(), '', 'DESC', '', '', '', '', '', '', '', '', '', '3', 'posts' );
¥
22 mrigby Jun 21, 2006 13:41
Yabba,
Thank you very much. I really appreciate all your help. I will upgrade to 0.9.2 (sparkle) first, then add the code you gave me. Many thanks and I will probably have additional questions at some point. :)
23 yabba Jun 21, 2006 13:49
No problem ;)
¥
24 kade Jul 23, 2006 16:34
Does this code work for a subdomain? I'm having trouble with it. Thanks.
-Kai
25 yabba Jul 23, 2006 18:10
It shouldn't be affected by being on a subdomain. What version of b2evo are you running, do you have a link to the subdomain where it fails and how is it failing?
¥
26 tycho Jul 26, 2006 20:12
How can i use the following code and limit it so it only shows a maximum of x posts?
<?php
require(dirname(__FILE__).'/evocore/_main.inc.php');
$ItemList = & new ItemList( 1, '', '', '', '', '', '', '', 'DESC');
while( $Item = $ItemList->get_item() )
{
echo '<li class="feed">
<a href="';
$Item->permalink();
echo '" title=""><span class="feed">'
.( $Item->title ? format_to_output( $Item->title ) : 'Sans titre' )
.'</span></a><br />
<span class="feed">'
."\n\r"
.'</span></li>'."\n\r";
}
?>
edit: How to do that without depending on the post limits set within the blog?
27 totof Jul 26, 2006 23:32
Hi,
Here is the code I use to display the 5 last posts :
<?php
require(dirname(__FILE__).'/evocore/_main.inc.php');
include ('conf/config.inc.php');
$connexion = mysql_connect($host,$user,$password);
if ($connexion>0) echo "";
else die ('pas de connexion active');
mysql_select_db($name,$connexion);
$sql="SELECT * from evo_posts ORDER BY post_ID DESC LIMIT 5";
mysql_query($sql) or die('Erreur SQL !'.$sql.''.mysql_error());
$result=mysql_query($sql);
$ItemList = & new ItemList( 1, '', '', '', '', '', '', '', 'DESC');
echo '<br />';
echo '<ul style="margin: 0 ;padding: 0 ;list-style-type: none ; margin-left:15px;">';
$Compteur=0;
while( $Item = $ItemList->get_item() )
{
?>
<li class="feed">
<a href="<?php $Item->permalink() ?>" title="Lire l'article en entier"><?php $Item->title( '', '', false ); ?></a>
</li>
<?php
$post_title = mysql_result($result , $Compteur , "post_title");
if ((strlen($post_title) == 0) && (strlen($post_content) != 0)) {
$post_title="Sans titre";
echo "<a href=\"$post_urltitle\" title=\"lire l'article en entier\"><span class=\"feed\">$post_title</span></a><br />";
}
$Compteur ++;
}
mysql_close();
echo '</ul>'
?>
In the line
$sql="SELECT * from evo_posts ORDER BY post_ID DESC LIMIT 5";
You can choose how many post you want to display.
in my case, I display the 5 lasts.
Hope this help
28 noahm Jun 13, 2007 18:35
I'm trying to perform this in 1.9.3. i have an index page in my root dir that calls a php summary file in /blogs/. adapted for 1.9.3 using the summary.php file, the code looks like this:
<?php
require_once dirname(__FILE__).'/conf/_config.php';
require_once $inc_path.'_main.inc.php';
?>
<?php // --------------------------- BLOG LIST -----------------------------
for( $blog=blog_list_start();
$blog!=false;
$blog=blog_list_next() )
{ # by uncommenting the following lines you can hide some blogs
if( $blog == 1 or $blog == 3 or $blog == 4) continue; // Hide blog 1...
?>
<h3><a href="<?php blog_list_iteminfo('blogurl', 'raw' ) ?>" title="<?php blog_list_iteminfo( 'shortdesc', 'htmlattr'); ?>"><?php blog_list_iteminfo( 'name', 'htmlbody'); ?></a></h3>
<ul>
<?php // Get the 3 last posts for each blog:
$BlogBList = & new ItemList( $blog, '', '', '', '', '', array(), '', 'DESC', '', 3, '', '', '', '', '', '', '', 'posts' );
while( $Item = $BlogBList->get_item() )
{
?>
<li lang="<?php $Item->lang() ?>">
<?php $Item->issue_date() ?>:
<?php $Item->permanent_link( '#title#' ) ?>
</li>
<?php
}
?>
<li><a href="<?php blog_list_iteminfo('blogurl', 'raw' ) ?>"><?php echo T_('More posts...') ?></a></li>
</ul>
<?php
}
?>
this code works when i view it alone.
however, because i'm calling it outside of the /blogs/ folder, it's choking on the code... probably because of a bad reference. i've tracked the place it dies to the GeneralSettings() function in /inc/MODEL/settings/_gerenalsettings.class.php.
any ideas how i might remedy this problem?
29 noahm Jun 13, 2007 21:41
solved my own problem: my index file is a page handler that calls a function that i defined to build the pages with includes. i found out that you can't call B2E pages within another function.
so, instead, i used the b_start(), ob_get_contents() and ob_end_clean() to read my blog list file above into a variable and then echoed the variable in the function. neat trick...
30 akgbob Jul 04, 2007 07:35
noahm wrote:
solved my own problem: my index file is a page handler that calls a function that i defined to build the pages with includes. i found out that you can't call B2E pages within another function.
so, instead, i used the b_start(), ob_get_contents() and ob_end_clean() to read my blog list file above into a variable and then echoed the variable in the function. neat trick...
Hi noahm,
Can you post the full code you used to get it working?
Cheers!
31 skawdiver Jul 09, 2007 14:25
<?php
require_once dirname(__FILE__).'/conf/_config.php';
require_once $inc_path.'_main.inc.php';
?>
<?php // --------------------------- BLOG LIST -----------------------------
for( $blog=blog_list_start();
$blog!=false;
$blog=blog_list_next() )
{ # by uncommenting the following lines you can hide some blogs
if( $blog == 1 or $blog == 3 or $blog == 4) continue; // Hide blog 1...
?>
<h3><a href="<?php blog_list_iteminfo('blogurl', 'raw' ) ?>" title="<?php blog_list_iteminfo( 'shortdesc', 'htmlattr'); ?>"><?php blog_list_iteminfo( 'name', 'htmlbody'); ?></a></h3>
<ul>
<?php // Get the 3 last posts for each blog:
$BlogBList = & new ItemList( $blog, '', '', '', '', '', array(), '', 'DESC', '', 3, '', '', '', '', '', '', '', 'posts' );
while( $Item = $BlogBList->get_item() )
{
?>
<li lang="<?php $Item->lang() ?>">
<?php $Item->issue_date() ?>:
<?php $Item->permanent_link( '#title#' ) ?>
</li>
<?php
}
?>
<li><a href="<?php blog_list_iteminfo('blogurl', 'raw' ) ?>"><?php echo T_('More posts...') ?></a></li>
</ul>
<?php
}
?>
Can this code be modified to display:
Post from say blog 1 and 3, output to a single list, ordered by date (not by blog)
Is that possible ?
32 adriscoll Sep 07, 2008 01:41
this is a great subject matter. anyone have an updated way to do this with the new versions (2.x)?
33 akgbob Feb 02, 2009 23:16
adriscoll wrote:
this is a great subject matter. anyone have an updated way to do this with the new versions (2.x)?
bump
34 bhaal Mar 16, 2009 23:16
This is definitely in need of an update (looking at you ¥åßßå!).
In my case, the blog is just one 'page' of the entire site, and I'd like to display the latest x number of posts to the home page.
I ended up trying to use/modify the code is summary.php with some success.
However, the home page opens a completely different mySQL database for it's own content - and now the B2 database as well.
I get a 'Cannot modify header information' error now. Bleh. When the home page is first opened, this error appears above the list of blog posts. If I then navigate to the blog page, then back to the home page, the error is gone.
There error says it is occuring in '_session.class.php'. As far as I can tell, this particular file isn't sending new header info.
Of course, I've played with the order in which things are loaded, but no love can be found :(
Is there updated code to accomplish this task? Most (if not all) of the examples in this thread are for older versions. ('/evocore/_main.inc.php' doesn't exist anymore, for example)
Thanks for letting me rant, and any help is greatly appreciated!
35 rasield May 29, 2009 04:05
Not certain how much help this will be, but thanks to reading through this thread to try to solve my own problem, I think I may have a fix of sorts. I also used the summary.php file as my base and only did minor tweaks to it. It seems to work well enough for my purposes and I hope it does similar for you. For the record, I am using version 2.4.5
<?php // --------------------------- BLOG LIST -----------------------------
load_class('items/model/_itemlist.class.php');
$BlogCache = & get_Cache( 'BlogCache' );
$blog_array = $BlogCache->load_public( 'ID' );
foreach( $blog_array as $blog )
{ // Loop through all public blogs:
# by uncommenting the following lines you can hide some blogs
if( $blog != 5 ) continue; //Hide blog 1 2 3 5 6
/**
* @var Blog
*/
$l_Blog = & $BlogCache->get_by_ID( $blog );
?>
<ul>
<?php // Get the 5 last posts for each blog:
$BlogBList = & new ItemList2( $l_Blog, NULL, 'now', 5 );
$BlogBList->set_filters( array(
'order' = > 'DESC',
'unit' = > 'posts',
) );
// Run the query:
$BlogBList->query();
while( $Item = & $BlogBList->get_item() )
{
?>
<li lang="<?php $Item->lang() ?>">
<?php
$Item->issue_date( array(
'before' = > ' ',
'after' = > ' ',
'date_format' = > '#',
) );
$Item->title( array(
'link_type' = > 'permalink',
) );
?>
<span class="small"><?php $Item->content() ?></span>
</li>
<?php
}
?>
<li><a href="<?php echo $l_Blog->gen_blogurl(); ?>"><?php echo T_('More posts...') ?></a></li>
</ul>
<?php
}
// ---------------------------------- END OF BLOG LIST --------------------------------- ?>
For the record, I am using version 2.4.5
Try something like this :-
¥