SimplePortal

Customization => Blocks and Modifications => Topic started by: ccbtimewiz on October 29, 2015, 08:47:50 PM

Title: Sticky Articles (display specific articles first)
Post by: ccbtimewiz on October 29, 2015, 08:47:50 PM
Sticky Articles

SMF 2.0 | SP 2.3.6

What this modification will do is allow you to define articles that will always appear first on the articles list displayed on your portal.

Might make $article_order no longer a hardcoded array and implement into article system itself if developers don't beat me to it.

Open /Sources/PortalBlocks.php

Find:
Code: [Select]
if (empty($image))
Replace with:
Code: [Select]
/*
Usage:
$article_order (array)
- contains a numerical list of topic ids (articles) you want stickied
- the order of stickies is the order of the array
- to get a topic id, hover over it and look at the link for ?topic=xxx
- alternatively you can look at the database for id_topic under smf_messages

Example:
$article_order = array(13, 11, 12, 8, 9, 10, 5, 14, 6);
*/

$article_order = array();

/*
*
*/

$new_articles = array();
$article_order = array_unique($article_order);

foreach ($article_order as $id)
{
foreach ($articles as $article)
{
if ($article['id'] == $id)
$new_articles[] = $article;
}
}

foreach ($articles as $article)
{
if (!in_array($article['id'], $article_order))
$new_articles[] = $article;
}

$articles = $new_articles;

if (empty($image))
Title: Re: Sticky Articles (display specific articles first)
Post by: ramzesito on October 31, 2015, 04:05:38 PM
Sorry, but in my case this code does not work,
article order didn't change

Did you test on SP 2.3.6?
Title: Re: Sticky Articles (display specific articles first)
Post by: ccbtimewiz on October 31, 2015, 05:26:19 PM
Did you follow the instructions?
Title: Re: Sticky Articles (display specific articles first)
Post by: ♦ Ninja ZX-10RR ♦ on October 31, 2015, 08:01:22 PM
I can confirm it works as it worked on my test site, nice block Sayaka ;)
Title: Re: Sticky Articles (display specific articles first)
Post by: ramzesito on November 09, 2015, 12:02:52 PM
I really would like to fix this problem,

I want the article to be sticked "Бескамерная резина: плюсы и минусы."

see http://www.sportgen.ru/forum/

my code in /forum/Sources/PortalBlocks.php:

Code: [Select]
/*
Usage:
$article_order (array)
- contains a numerical list of topic ids (articles) you want stickied
- the order of stickies is the order of the array
- to get a topic id, hover over it and look at the link for ?topic=xxx
- alternatively you can look at the database for id_topic under smf_messages

Example:
$article_order = array(13, 11, 12, 8, 9, 10, 5, 14, 6);
*/

$article_order = array(2285);

/*
*
*/

$new_articles = array();
$article_order = array_unique($article_order);

foreach ($article_order as $id)
{
foreach ($articles as $article)
{
if ($article['id'] == $id)
$new_articles[] = $article;
}
}

foreach ($articles as $article)
{
if (!in_array($article['id'], $article_order))
$new_articles[] = $article;
}

$articles = $new_articles;

if (empty($image))
......

it doesn't work... (
how can I diagnose a problem?
Title: Re: Sticky Articles (display specific articles first)
Post by: ccbtimewiz on November 09, 2015, 07:55:55 PM
That's strange, it should output that topic first.

Do you have any errors in your Forum Error Log? Can you post the file PortalBlocks.php here as an attachment?
Title: Re: Sticky Articles (display specific articles first)
Post by: ramzesito on November 10, 2015, 03:40:37 PM
Forum Error log is empty,
portalBlocks.php attached...
Title: Re: Sticky Articles (display specific articles first)
Post by: ccbtimewiz on November 12, 2015, 06:44:56 PM
Have you tried clearing your forum's cache?
Title: Re: Sticky Articles (display specific articles first)
Post by: ramzesito on November 15, 2015, 03:53:01 AM
yes, I have cleared...
how can I trace the code step by step to point problem?
Title: Re: Sticky Articles (display specific articles first)
Post by: ramzesito on November 18, 2015, 02:46:11 PM
why don't you release a real mod?
you will get more users for it and mor testers  ;)
Title: Re: Sticky Articles (display specific articles first)
Post by: ♦ Ninja ZX-10RR ♦ on November 18, 2015, 02:55:55 PM
Well it's a block, it's not meant to be a mod since it strictly requires SimplePortal to work.
Title: Re: Sticky Articles (display specific articles first)
Post by: ccbtimewiz on November 18, 2015, 08:55:52 PM
I'm going to see through the syntax and see if I made a mistake when it handles just one article.
Title: Re: Sticky Articles (display specific articles first)
Post by: ramzesito on December 06, 2015, 09:49:04 AM
I'm going to see through the syntax and see if I made a mistake when it handles just one article.

Sayaka?
Title: Re: Sticky Articles (display specific articles first)
Post by: emanuele on December 06, 2015, 03:42:39 PM
I guess it works as long as the article is shown on the page.
Being the "Бескамерная" article on the third page it's not retrieved from the database and as such not displayed on the first page.
If you want to have a "really" sticky article, you need an additional query to retrieve the data.
Title: Re: Sticky Articles (display specific articles first)
Post by: ccbtimewiz on December 07, 2015, 10:32:36 PM
Ahhh, I see now. I'll see into making that adjustment.
Title: Re: Sticky Articles (display specific articles first)
Post by: ramzesito on December 25, 2015, 04:04:11 AM
Ahhh, I see now. I'll see into making that adjustment.

Sayaka? )
Title: Re: Sticky Articles (display specific articles first)
Post by: qwert321 on January 10, 2016, 02:43:19 PM
http://custom.simplemachines.org/mods/index.php?mod=3425

it can be modded to order articles.

I did it two years ago but my work is a hatched job at best

I cannot uninstall as I modded after I installed.

If i had to do it again I would mod the files to my liking then install.
SimplePortal 2.3.8 © 2008-2024, SimplePortal