1

Topic: Show news only in session language

Hi,

Yesterday there was a topic someone (i think rombest) asking how it would be possible to show news only in users language. But now i can not find that topic. I hope it was not a dream.

Here the solution is:

1. Open ext.news.php

Find:

        $result = $DB->query("SELECT * FROM " . DB_PREFIX . "news WHERE active='1' ORDER BY $orderby $orderdir LIMIT $limit");

Replace:

        $filter_lng = '<div class="'.$SESSION->conf['language'].'-news"';
        $result = $DB->query("SELECT * FROM " . DB_PREFIX . "news WHERE active='1' AND body LIKE '$filter_lng%' ORDER BY $orderby $orderdir LIMIT $limit");

2. Open lib.news.php

Find:

            $result = $DB->query("SELECT * FROM " . DB_PREFIX . "news WHERE active='1' ORDER BY postdate DESC, news_id DESC LIMIT " . (($page - 1) * $PREFS->conf['news_per_page']) . ", " . $PREFS->conf['news_per_page']);

Replace:

$filter_lng = '<div class="'.$SESSION->conf['language'].'-news"';
$result = $DB->query("SELECT * FROM " . DB_PREFIX . "news WHERE active='1' AND body LIKE '$filter_lng%' ORDER BY postdate DESC, news_id DESC LIMIT " . (($page - 1) * $PREFS->conf['news_per_page']) . ", " . $PREFS->conf['news_per_page']);

(For totalpages)
Find:

$result = $DB->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "news WHERE active='1'");

Replace:

$filter_lng = '<div class="'.$SESSION->conf['language'].'-news"';
$result = $DB->query("SELECT COUNT(*) as total FROM " . DB_PREFIX . "news WHERE active='1' AND body LIKE '$filter_lng%'");

3. While publishing news, at body section use the structure below.

Example English: <div class="english-news">English news body bla bla bla... </div>

Example French: <div class="french-news">French news body bla bla bla... </div>

Example Turkish: <div class="turkish-news">Turkish news body bla bla bla... </div>

If you have any questions feel free to ask.

Note: This could be done with adding an extra field for news too. But i think this is easier.

Important: Be sure news body starts with <div class=" not with <br>

Last edited by mystec (2009-12-01 03:59:04)

2

Re: Show news only in session language

Nice and easy to implement solution. Approved! smile

www.vldMagic.com - first choice customizations help desk
www.vldCrowd.com - vldPersonals admins community

3

Re: Show news only in session language

radioact wrote:

Nice and easy to implement solution. Approved! smile

Yes, this is the easiest way i think, sure not the most professional one smile

4

Re: Show news only in session language

It's good enough and easy to reapply on every new vldP version if it comes.
One suggestion to try:

AND body LIKE '%$filter_lng%'

Could be:

AND body LIKE '$filter_lng%'

This will search only at beginning of news body.
Because of we put <div class="english-news"> at the start no need to seek it all over the news body text.

www.vldMagic.com - first choice customizations help desk
www.vldCrowd.com - vldPersonals admins community

5

Re: Show news only in session language

radioact wrote:

It's good enough and easy to reapply on every new vldP version if it comes.
One suggestion to try:

AND body LIKE '%$filter_lng%'

Could be:

AND body LIKE '$filter_lng%'

This will search only at beginning of news body.
Because of we put <div class="english-news"> at the start no need to seek it all over the news body text.

Edited it. I hope people wont add <div class=".. after that default <br>

6

Re: Show news only in session language

Oh, actually they will smile

www.vldMagic.com - first choice customizations help desk
www.vldCrowd.com - vldPersonals admins community

7

Re: Show news only in session language

radioact wrote:

Oh, actually they will smile

We will see:)

8

Re: Show news only in session language

It works PERFECT. I recommand it !

9

Re: Show news only in session language

rombest wrote:

It works PERFECT. I recommand it !

Nice to see it is working:)

I have forgotten totalnews because i did not have enough news. I saw it on your site and added it. It will be totally done after replacing one more line. See the first message step 2 please.

10

Re: Show news only in session language

If i want add Last 5 News on homepage.tpl is possible to have content respecting sessions language too, like in /news/ page ?

11

Re: Show news only in session language

I suppose it is. Just edit ext.news.php similar way.

www.vldMagic.com - first choice customizations help desk
www.vldCrowd.com - vldPersonals admins community

12

Re: Show news only in session language

radioact wrote:

I suppose it is. Just edit ext.news.php similar way.

This i have allready done, i have news page content respecting sessions language.

But if i add in homepahe.tpl  this :

    <h3 class="news">{lang:"core","home_latest_news"}</h3>
    <div class="block news">
        {news:limit=5,cache_time=0}
    </div>

I get news in all languages, so no respect for session language on homepage.

13

Re: Show news only in session language

Very good customization - thanks, mystec.
But not for all,  minimal HTML knowledge is required.
By the way, if used HTML editor for addition  <div> to news (it's  logically to use it), assignment of variable must be:
$filter_lng = '<DIV class='.$SESSION->conf['language'].'-news';
because HTML editor remove " " and write "DIV" instead of "div".