 |
| View previous topic :: View next topic |
| Author |
Message |
skytoheaven Guest
|
Posted: Mon Oct 17, 2005 3:44 pm Post subject: limiting number of popular posts |
|
|
How do I limit the number of popular posts?
I don't know very much code, and I couldn't find the answer anywhere.
Any help would be greatly appreciated.
Right now, I have the following code:
| Code: | {popularposts}
{if $pposts != ''}
<ul><li id="mostpopularessays">Most Popular Essays
<ul>
{foreach from=$pposts key=key item=hits}
<li><a href="{$hits.url}" title="{$hits.title}">{$hits.title|truncate:25:"..."}</a>: {$key}</li>
{/foreach}
</ul>
</li></ul>
{/if} |
My site is at [url]skytoheaven.blogsome.com[/url]
Thanks a lot for any help! |
|
| Back to top |
|
Shana
Joined: 19 Sep 2005 Posts: 955 Location: Lincolnshire, UK
|
Posted: Mon Oct 17, 2005 9:21 pm Post subject: |
|
|
Although I don't use the Popular posts code, this is the code for last posts and maybe that will apply to Popular posts as well.
| Code: | {lastposts posts='6'}
{if $lastposts != ''}
<h2>Most Recent Posts</h2>
<ul>
{foreach from=$lastposts key=id item=title}
<li><a href="{get_permalink id=$id}" title="{$title}">{$title|truncate:25:"..."}</a></li>
{/foreach}
</ul>
</li></ul>
{/if} |
Shana _________________ it's all beta - a basic guide to using Blogsome
please don't PM me with questions that belong in the forum |
|
| Back to top |
|
schinckel
Joined: 03 Apr 2005 Posts: 1238 Location: Adelaide, Australia
|
Posted: Tue Oct 18, 2005 1:21 am Post subject: |
|
|
The posts argument doesn't work: I'll have to wait until I get home before I check out what the argument needs to be called.
(Or, you could try downloading the WP-Mu source, and find it for yourself, if you know how to read PHP a little) _________________ Blogsome Forum: Rules/Search
WordPress Codex; Smarty Tags Docs |
|
| Back to top |
|
skytoheaven Guest
|
Posted: Tue Oct 18, 2005 6:27 am Post subject: |
|
|
Thanks Shana, but I did try the posts='6' before, but it didn't work. Thanks for trying to help though!
Schinckel - I don't know any PHP . I would really appreciate it if you could find the argument, when you have the time.
By the way, even if you don't find the answer, I still also want to say "Thank You." It's amazing that you help out so many people in these forums - especially if you aren't really getting paid, which is what I assume. You & zheaton are doing a great job - Best of luck to you both!
yours sincerely,
evan
skytoheaven.blogsome.com |
|
| Back to top |
|
schinckel
Joined: 03 Apr 2005 Posts: 1238 Location: Adelaide, Australia
|
Posted: Tue Oct 18, 2005 9:11 am Post subject: |
|
|
I wasn't able to figure out whether it will in fact take any arguments. I don't think it does, but I've included the source in case anyone else is able to find a possible argument:
| Code: | /*
* Smarty plugin
* -------------------------------------------------------------
* File: function.popularposts.php
* Type: function
* Name: popularposts
* Purpose: outputs an image from the images/ directory.
* -------------------------------------------------------------
*/
function getlinks( $wpblog )
{
global $wpdb, $site;
$s = strlen( $site );
$sql = "SELECT visitURL, count( * ) AS c, substring_index( substring_index(
visitURL, '/', ".($s+1)." ), '/', -1 ) as postID
FROM referer_visitLog
WHERE blogID = '".$wpblog."'
AND visitURL NOT LIKE '%/archives/%'
AND visitURL LIKE '%/'
GROUP BY blogID, visitURL
ORDER BY c DESC
LIMIT 0,30";
$results = $wpdb->get_results($sql);
if( $results )
{
reset( $results );
while( list( $key, $t ) = each( $results ) )
{
if( substr( $t->visitURL, -9 ) == 'index.php' )
$t->visitURL = substr( $t->visitURL, 0, -9 );
$hits[ $t->visitURL ] += $t->c;
}
arsort( $hits );
$hits = array_flip( $hits );
reset( $hits );
while( list( $key, $val ) = each( $hits ) )
{
if( substr( $val, -1 ) == '/' )
{
$post_name = substr( $val, 0, -1 );
$post_name = substr( $post_name, strrpos( $post_name, '/' ) + 1
);
$sql = "SELECT post_title
FROM ".$wpdb->posts."
WHERE post_name = '".$post_name."'";
$results = $wpdb->get_results($sql);
if( $results )
{
$links[ $key ] = array( "url" => $val, "title" => stripslash
es( $results[0]->post_title ) );
}
}
}
}
else
{
$links = false;
}
return $links;
}
function smarty_function_popularposts($params, &$smarty)
{
global $wpblog, $site;
extract( $params );
if( @include_once( "Cache/Function.php" ) )
{
$cache = new Cache_Function( 'file', array('cache_dir' => "/var/tmp/cach
e/", 'filename_prefix' => 'popularposts_cache_' ), 3600 );
$links = $cache->call( "getlinks", $wpblog );
}
else
{
$links = getlinks( $wpblog, $site );
}
$smarty->assign( "pposts", $links );
}
?> |
_________________ Blogsome Forum: Rules/Search
WordPress Codex; Smarty Tags Docs |
|
| Back to top |
|
schinckel
Joined: 03 Apr 2005 Posts: 1238 Location: Adelaide, Australia
|
Posted: Tue Oct 18, 2005 10:25 am Post subject: |
|
|
Actually, it may be possible to use Smarty to iterate only over a certain number of items in an Array.
I'm playing around with {section} instead of {foreach}, but since this array seems to use the number of hits as the key, it's turning out to be difficult. _________________ Blogsome Forum: Rules/Search
WordPress Codex; Smarty Tags Docs |
|
| Back to top |
|
schinckel
Joined: 03 Apr 2005 Posts: 1238 Location: Adelaide, Australia
|
Posted: Tue Oct 18, 2005 10:39 am Post subject: |
|
|
Bingo!
| Code: | {popularposts}
{if $pposts != ''}
<h2>Most Popular Posts</h2>
<ul>{counter assign=pp print=0}
{foreach from=$pposts key=key item=hits}
{counter}
{if $pp <= 6}
<li><a href="{$hits.url}" title="{$hits.title}">{$hits.title|truncate:25:"..."}</a>: {$key}</li>
{/if}
{/foreach}
</ul>
{/if} |
Note that the {if $pp <= 6} clause will cause 5 post links to appear. _________________ Blogsome Forum: Rules/Search
WordPress Codex; Smarty Tags Docs |
|
| Back to top |
|
skytoheaven Guest
|
|
| Back to top |
|
ioreyes
Joined: 23 Nov 2005 Posts: 4
|
Posted: Wed Nov 23, 2005 9:14 am Post subject: couldn't get it to work |
|
|
Hi --
I've been tweaking the "dots" template by Alex King and have made some cosmetic changes to it here: http://issyreyes.blogsome.com. I'm a newbie at this so it took me hours and hours and still more hours to get all those changes in there.
I haven't moved from LJ into blogsome yet because I'd like to try out WP, get used to it, and get the whole everything set up before I move--that's why all my posts are test posts.
Anyway, how do I apply the code above to my template? I'd like to limit the number of popular posts, too.
Oh and how do I put links on the top of my page?
Thanks for any help  |
|
| Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|