11
rowdie
Re: Recent News titles to include topic?
  • 2005/1/3 21:29

  • rowdie

  • Just can't stay away

  • Posts: 846

  • Since: 2004/7/21


That would work, but adding an extra sql call to every row would also add to the page generation time.

My code works, and it's not as complicated as it looks... try it...

Rowd

12
jfmoore
Re: Recent News titles to include topic?
  • 2005/1/3 21:40

  • jfmoore

  • Quite a regular

  • Posts: 360

  • Since: 2004/6/6 5


Thanks so much rowdie and dionesku for the answers. I have been looking for this info for a while.

I am a little confused, though, because these two suggestions seem to be different. Is there more than one way to do this, and, if so, which, if either, is better???

JFM

13
jfmoore
Re: Recent News titles to include topic?
  • 2005/1/4 0:38

  • jfmoore

  • Quite a regular

  • Posts: 360

  • Since: 2004/6/6 5


Quote:

rowdie wrote:
That would work, but adding an extra sql call to every row would also add to the page generation time.

My code works, and it's not as complicated as it looks... try it...

Rowd


Thanks again! I'll give it a try and post the results.

JFM

14
jfmoore
Re: Recent News titles to include topic?
  • 2005/1/4 4:41

  • jfmoore

  • Quite a regular

  • Posts: 360

  • Since: 2004/6/6 5


Rowdie,

It works! Simple, quick, effective! What else is there to say, but thanks? I would have sworn one would have had to edit the block template, so that shows how much I know. And, just to prove that no good deed goes unpunished, here's another question. Seriously, though, since the question may have to do with the hack which you devised, the best time to ask is probably while it is still fresh:

Now, thanks to you, the topic is showing up in the Recent News block. If I were to later want to bold or change the color of the text for the topic only in this block, where would I do this?

JFM

15
dionesku
Re: Recent News titles to include topic?
  • 2005/1/4 15:50

  • dionesku

  • Just popping in

  • Posts: 3

  • Since: 2004/12/23


I think that with Rowdie's code you can't do that since the TOPIC and the STORY title is only one piece of text and one link (or isn't it); and also can't make a separate link to Topic's page.

With my code you have separate pieces of text and links for TOPIC and STORY and so, you cand do whatever you ont with them separately (change the order they apear, change the font, color or whatever you want independently of each other).

So, for may code, simply give a class to the topic link in the template file, like this:

<[color=ff0000]class="yourClass"[/colorhref="<{$xoops_url}>/modules/news/index.php?storytopic=<{$news.topic_id}>"><{$news.topic_title}></a>


Than, just add ".youreClass" into your theme style.css file (of course, with variants for ".youreClass a", ".youreClass a:hover" etc.)

I think that should do it!

16
rowdie
Re: Recent News titles to include topic?
  • 2005/1/4 17:08

  • rowdie

  • Just can't stay away

  • Posts: 846

  • Since: 2004/7/21


I missed your post earlier, JFM... sorry

To make the topic separate you will need to add ', topicid ' to both of the sql statements, like this:
topic_titletopicid FROM


Then change the $topic_title and $topic lines to this:
$topic_title $myts->makeTboxData4Show($myrow["topic_title"]);
        
$title $myts->makeTboxData4Show($myrow["title"]);
    
$topic_id $myrow["topicid"];
    if ((
strlen($title) + strlen($topic_title)) > $options[2]) {
        
$title xoops_substr($title,0,$options[2]+3);
    }
        
$news['topic_title'] = $topic_title;
        
$news['title'] = $title;
        
$news['topic_id'] = intval($topic_id);
        
$news['id'] = $myrow['storyid'];


By doing it this way it still uses the preference you set for restricting the length of the news title - the difference being that it uses that setting on topic and title, as one line.

Finally you will need to change the template news_block_new.html
Between the foreach lines, put this line:
<li><a href="<{$xoops_url}>/modules/news/index.php?storytopic=<{$news.topic_id}>"><{$news.topic_title}></a> :: <a href="<{$xoops_url}>/modules/news/article.php?storyid=<{$news.id}>"><{$news.title}></a> (<{$news.date}>)</li>


If you want to add different styles to topic and title, assign a different class to each one, as dionesku outlined above.

If you don't want to have the topic name as a link, then just remove the "a" html tag - look online for html tutorials if you need help with that, there are tons of them and they explain it much better than I can.

Rowd

For reference, here's the whole function:
function b_news_top_show($options) {
    global 
$xoopsDB;
    
$myts =& MyTextSanitizer::getInstance();
    
$block = array();
    
$options_new array_slice $options);
    
$topicpick '('.implode ','$options_new ).')';
    if ( 
$options[3] == ) {
        
$sql "SELECT storyid, title, published, expired, counter, topic_title, topicid FROM
              "
.$xoopsDB->prefix("stories")." , ".$xoopsDB->prefix("topics")." t WHERE published < ".time()."
              AND published > 0 AND (expired = 0 OR expired > "
.time().") AND topicid = t.topic_id ORDER BY
              "
.$options[0]." DESC";
    }
    else {
        
$sql "SELECT storyid, title, published, expired, counter, topic_title, topicid FROM
                   "
.$xoopsDB->prefix("stories")." , ".$xoopsDB->prefix("topics")." t WHERE published < ".time()."
                   AND published > 0 AND (expired = 0 OR expired > "
.time().") AND topicid in
                   "
.$topicpick." AND topicid = t.topic_id ORDER BY ".$options[0]." DESC";
    }    
$result $xoopsDB->query($sql,$options[1],0);
    while ( 
$myrow $xoopsDB->fetchArray($result) ) {
        
$news = array();

    
$topic_title $myts->makeTboxData4Show($myrow["topic_title"]);
        
$title $myts->makeTboxData4Show($myrow["title"]);
    
$topic_id $myrow["topicid"];
    if ((
strlen($title) + strlen($topic_title)) > $options[2]) {
        
$title xoops_substr($title,0,$options[2]+3);
    }
        
$news['topic_title'] = $topic_title;
        
$news['title'] = $title;
        
$news['topic_id'] = intval($topic_id);
        
$news['id'] = $myrow['storyid'];
        if ( 
$options[0] == "published" ) {
            
$news['hits'] = formatTimestamp($myrow['published'],"s");
            
$news['date'] = formatTimestamp($myrow['published'],"s");
        } elseif ( 
$options[0] == "counter" ) {
            
$news['hits'] = $myrow['counter'];
            
$news['date'] = $myrow['counter'];
        }
        
$block['stories'][] = $news;
    }
    return 
$block;
}

17
jfmoore
Re: Recent News titles to include topic?
  • 2005/1/24 21:27

  • jfmoore

  • Quite a regular

  • Posts: 360

  • Since: 2004/6/6 5


dionesku,

With your mod, if, on the block admin page, you select certain topics to be displayed, then the topic titles in the block disappear. How can I change this to display either "all topics" or all selected topics?

Thanks.

JFM

18
jfmoore
Re: Recent News titles to include topic?
  • 2005/1/26 15:58

  • jfmoore

  • Quite a regular

  • Posts: 360

  • Since: 2004/6/6 5


Nevermind. I figurered it out...I think.

Quote:

dionesku wrote:
Try this:

Modify the file modules/news/blocks/news_top.php
this way:

insert ", topicid" between "counter" end "FROM" in this line:
$sql = "SELECT storyid, title, published, expired, counter FROM like this
$sql = "SELECT storyid, title, published, expired, counter, topicid FROM


You must also include ", topicid" in the same location in the similar line after the "else" statement.

JFM

19
kavaXtreme
Re: Recent News titles to include topic?
  • 2005/2/28 10:38

  • kavaXtreme

  • Repository Maintainer

  • Posts: 110

  • Since: 2005/1/17


Thanks for the thread guys! This is EXACTLY what I want to do. I'm running into a few problems though, quite possibly because I don't have a clue about PHP.

1. I'm guessing this info is not about the News 1.3RC2 news_top.php? Could someone update the info for that version (or would it be better to just wait for the final version)?

2. Also, would it be too much trouble to ask someone to re-post the code as it looks in its final version after all the updates? Starting line numbers would be VERY helpful.

Sorry for questions that must seem very simple to you guys. I'm just out of my league when it comes to PHP.

20
kavaXtreme
Re: Recent News titles to include topic?
  • 2005/3/9 23:15

  • kavaXtreme

  • Repository Maintainer

  • Posts: 110

  • Since: 2005/1/17


anybody...? Please, please, please, PUULLLEEEASE!!!

My biggest problem is that I can't find the "$sql" thingy where it's supposed to be, so I can't add the topic_title call. I've been trying to get my mind around this, so the rest is beginning to make sense to me.

Login

Who's Online

127 user(s) are online (83 user(s) are browsing Support Forums)


Members: 0


Guests: 127


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits