Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: Blog: having a different -php menu_articles- function  (Read 6125 times)

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Blog: having a different -php menu_articles- function
« on: May 14, 2008, 01:40:29 PM »

Hello all,
in my case (I suppose it's the same for most of us) visitors come from search engine so they land on a specific page.
In case of a blog you may have a "recent articles" box somewhere on your page.
That's good for teasing and more pages views.
So what Inspector?
The function used can have parameters such as:
Quote
<?php menu_articles(4,5); ?>
In that case I want to display only 5 articles starting from the 4th which has been published.

That's great when the visitor is on the home page where the last 4 articles are being displayed: he can see in a glance  the next articles which has been published.
But when he is in an article page, he should see the last 4 articles published.
So, we could have 2 different functions:
1/ when its a page
Quote
<?php menu_articles(0,5); ?>
2/ when on the blog home page, the next following articles:
Quote
<?php menu_articles(4,5); ?>

It's a detail you gonna say.
And you will be right: I love details.

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: Blog: having a different -php menu_articles- function
« Reply #1 on: May 17, 2008, 04:42:42 AM »

Hi Mr.Sven,

You can have :
- Next 5 articles
- Prev 5 articles

To work only in an article page.
- display articles newer that date of current article(ASC?) , limit 5
- display articles older than date of current article(DESC?) , limit 5

Queries are increased. You are sure?
Logged

Joost

  • Guest
Re: Blog: having a different -php menu_articles- function
« Reply #2 on: May 17, 2008, 05:44:20 AM »

Inspector,

Replace old function with this.

Code: [Select]
<?php
// MENU ARTICLES
function menu_articles($start$size) {
if (empty(
$_GET['category'])) $start s('article_limit');
$query '
SELECT
title,a.seftitle AS asef,date,
c.name AS name, c.seftitle AS csef
FROM '
.db('prefix').'articles AS a
LEFT OUTER JOIN '
.db('prefix').'categories as c
ON category = c.id
WHERE position = 1 AND a.published = 1 AND c.published ="YES"
ORDER BY date DESC LIMIT '
."$start$size";
$result mysql_query($query);
if (mysql_num_rows($result) === 0) {echo '<li>'.l('no_articles').'</li>';}
else {
while ($r mysql_fetch_array($result)) {
$date date(s('date_format'), strtotime($r['date']));
echo '<li><a href="'.db('website').$r['category'].'/'.$r['seftitle'].'/" title="'.$r['name'].' ('.$date.')">'.$r['title'].'</a></li>';
}}}

?>


Regards,

Cato
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: Blog: having a different -php menu_articles- function
« Reply #3 on: May 17, 2008, 06:03:51 AM »

Hi Joost,
Congratulations for your advanced queries...
Every time I see your queries, my brain give me `System error`!
For now, I can`t `Float with you`, :( maybe in future... the water is so cold... :P

I will need time to understand 1.7 version (is like a reset)....
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: Blog: having a different -php menu_articles- function
« Reply #4 on: May 17, 2008, 12:42:41 PM »

Hellooooo friends. Howdee?
the code you've posted, Joost, produce those URL: http://localhost/snews///

PS: what Cato is for? ???

Joost

  • Guest
Re: Blog: having a different -php menu_articles- function
« Reply #5 on: May 17, 2008, 02:28:11 PM »

Hellooooo friends. Howdee?
the code you've posted, Joost, produce those URL: http://localhost/snews///

PS: what Cato is for? ???

Sorry, a mistake, use this:


Code: [Select]
<?php

function menu_articles($start$size) {
if (empty(
$_GET['category'])) $start s('article_limit');
$query '
SELECT
title,a.seftitle AS asef,date,
c.name AS name, c.seftitle AS csef
FROM '
.db('prefix').'articles AS a
LEFT OUTER JOIN '
.db('prefix').'categories as c
ON category = c.id
WHERE position = 1 AND a.published = 1 AND c.published ="YES"
ORDER BY date DESC LIMIT '
."$start$size";
$result mysql_query($query);
if (mysql_num_rows($result) === 0) {echo '<li>'.l('no_articles').'</li>';}
else {
while ($r mysql_fetch_array($result)) {
$date date(s('date_format'), strtotime($r['date']));
echo '<li><a href="'.db('website').$r['csef'].'/'.$r['asef'].'/" title="'.$r['name'].' ('.$date.')">'.$r['title'].'</a></li>';
}}}
?>

From wikipedia
Quote
Cato Fong

Cato (spelled "Kato" in A Shot in the Dark) is Clouseau's house boy, and an expert in martial arts. It is unclear whether he believes Clouseau to be a great detective or whether he merely humors him. It is a running joke that he is instructed to unexpectedly attack Clouseau, to keep Clouseau's combat skills and vigilance sharp. If they are interrupted during such an attack (as by a telephone call), Cato ceases to project the image of assailant and becomes a well-disciplined valet.
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: Blog: having a different -php menu_articles- function
« Reply #6 on: May 18, 2008, 03:18:00 PM »

Okey okey Cato ;)
Does it work for you?
On my side I see no difference.

Joost

  • Guest
Re: Blog: having a different -php menu_articles- function
« Reply #7 on: May 18, 2008, 06:00:06 PM »

Maybe I've misunderstand what you want. The code is supposed to change the offset to 4 (actually the number that is set in article limit (admin settings)) when on home. Did you mean by any change, the first page of any category?
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: Blog: having a different -php menu_articles- function
« Reply #8 on: May 18, 2008, 06:22:46 PM »

My global category for the blog side is articles.

Joost

  • Guest
Re: Blog: having a different -php menu_articles- function
« Reply #9 on: May 18, 2008, 06:31:01 PM »

My global category for the blog side is articles.

I see. Here is quick and dirty (untested) solution:

Change the following line:

if (empty($_GET['category'])) $start = s('article_limit');

to

if (get_id('category') == 'articles') $start = s('article_limit');


new line updated (in case it is not working)
« Last Edit: May 18, 2008, 06:36:22 PM by Joost »
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: Blog: having a different -php menu_articles- function
« Reply #10 on: May 19, 2008, 09:34:57 AM »

You're a chef Mr Joost
It works perfectly.
So a karma is gonna be delivered!
Thank you so much Cato. ;)

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • “I'm a self-made man and worships my creator.”
    • p-ahlqvist.com
Re: Blog: having a different -php menu_articles- function
« Reply #11 on: May 19, 2008, 02:43:27 PM »

Cato = cat, eh ? You call Joost a cat, hehe... or the milder form - pussy, whuhaaaa... Ok, too much coffee again, no offense meant Joost ;)

Or am I looking for Gato, perhaps ?
Logged
"It's only dead fish that goes with the flow... "
Updated

Joost

  • Guest
Re: Blog: having a different -php menu_articles- function
« Reply #12 on: May 19, 2008, 04:09:50 PM »

Cato = cat, eh ? You call Joost a cat, hehe... or the milder form - pussy, whuhaaaa... Ok, too much coffee again, no offense meant Joost ;)

Or am I looking for Gato, perhaps ?

Here is a Yahoo result (Spanish Dictionary: translation of gato):


   1.  zoology cat, tomcat
   2. (gancho de hierro) clamp, vice
   3. (cric) jack
      gato hidráulico hydraulic jack
   4. colloquial (portamonedas) moneybag
   5. (ahorros) savings
   6. figurative, colloquial (ladrón) sneak thief, cat burglar
   7. (madrileño) native of Madrid, Madrilenian
   8. (hombre astuto) fox, slyboots
   9. America (molledo del brazo) fleshy part of the arm
  10. Argentina folk dance
  11. Mexico (propina) tip
  12. (sirviente) servant
  13. Peru open-air market
  14. Venezuela syphilis

Which one Pat?  ;D
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • “I'm a self-made man and worships my creator.”
    • p-ahlqvist.com
Re: Blog: having a different -php menu_articles- function
« Reply #13 on: May 20, 2008, 07:35:38 AM »

I'll have to go with Uno here... Although number 14 is luring ;)
Logged
"It's only dead fish that goes with the flow... "
Updated