Welcome to Geeklog, Anonymous Thursday, March 28 2024 @ 10:07 am EDT

Geeklog Forums

Topic name in story title


Status: offline

spiffin

Forum User
Newbie
Registered: 12/03/03
Posts: 5
Hello

Apologies for my stupidity but I'm trying to get the topic name to appear in a story title. For example if I had a topic called 'News' and a story called 'My birthday' I would like the story title to read 'News: My birthday'

Could someone please tell me which files to edit and where?

Thank you

spiffin
 Quote

Status: offline

Turias

Forum User
Full Member
Registered: 10/20/03
Posts: 807
Here's a quick hack to do what you want:

Open up lib-common.php,

in COM_article, find
Text Formatted Code
if( $_USER['noicons'] != 1 AND $A['show_topic_icon'] == 1 )



 


delete that entire if block and replace it with:

Text Formatted Code

$result = DB_query( "SELECT imageurl,topic FROM {$_TABLES['topics']} WHERE tid = '{$A['tid']}'" );
$T = DB_fetchArray( $result );

$topicname = htmlspecialchars( stripslashes( $T['topic'] ));
$article->set_var( 'story_topic_name_hack', $topicname );

if ( $_USER['noicons'] != 1 AND $A['show_topic_icon'] == 1 )
{
    $topicurl = $_CONF['site_url'] . '/index.php?topic=' . $A['tid'];
    if( !empty( $T['imageurl'] ))
    {
        if( isset( $_THEME_URL ))
        {
            $imagebase = $_THEME_URL;
        }
        else
        {
            $imagebase = $_CONF['site_url'];
        }
        $topicimage = '<img align="' . $_CONF['article_image_align']
                . '" src="' . $imagebase . $T['imageurl'] . '" alt="'
                . $topicname . '" title="' . $topicname . '" border="0">';
        $article->set_var( 'story_anchortag_and_image', '<a href="'
                . $topicurl . '">' . $topicimage . '</a>' );
        $article->set_var( 'story_topic_image', $topicimage );
    }
    $article->set_var( 'story_topic_id', $A['tid'] );
    $article->set_var( 'story_topic_name', $topicname );
    $article->set_var( 'story_topic_url', $topicurl );
}



 


Now, {story_topic_name_hack} is set. You can use this variable in public_html/layout/yourtheme/storytext.thtml and featuredstorytext.thtml to display the topic of that story. Just stick it before the story title in those files.
 Quote

Status: offline

spiffin

Forum User
Newbie
Registered: 12/03/03
Posts: 5
Thanks very much for your help.

That worked a treat.

spiffin
 Quote

Status: offline

geKow

Forum User
Full Member
Registered: 01/12/03
Posts: 445
I did it this way:
in storytext.thtml and featuredstorytext.thtml I replaced

{story_anchortag_and_image}
with
{story_topic_name}

geKow
 Quote

Status: offline

Turias

Forum User
Full Member
Registered: 10/20/03
Posts: 807
That only works if the story is set to show_topic_icon and if the user does not have noicons set. Otherwise, {story_topic_name} is undefined.

My hack makes sure that it is always defined.

Although, now that I think about it, my hack will probably make the user always see story icons, even if the user has set to turn them off. I'll update my hack shortly with a fix.
 Quote

Status: offline

Turias

Forum User
Full Member
Registered: 10/20/03
Posts: 807
There, that should fix the problems it had before. Make sure you update your code, spiffin.
 Quote

Status: offline

geKow

Forum User
Full Member
Registered: 01/12/03
Posts: 445
ok, I (PHP idiot) followed your way and it works. I have only one improvement: If you want the category be a link:
Text Formatted Code
<a class="storycat" href="{story_topic_url}">[{story_topic_name_hack}]</a>
 

(where the class is just my idea how to style that)

anyway, thanks for the improvement

geKow
 Quote

Status: offline

Turias

Forum User
Full Member
Registered: 10/20/03
Posts: 807
Careful. Again, {story_topic_url} is only set when the story is set to display its icon and when the user hasn't opted out of viewing those icons.

To do that correctly, you should create a new variable (like story_topic_url_hack) and set it before

Text Formatted Code
if ( $_USER['noicons'] != 1 AND $A['show_topic_icon'] == 1 )
 


in my code. That will guarantee that it is set no matter what the story or user preferences.
 Quote

Status: offline

geKow

Forum User
Full Member
Registered: 01/12/03
Posts: 445
arghh.. you are right Oops!

I go back into my corner
(don't mess with a coder)

edited a little later:
But if the site or usersettings are set to show no icons... you won't need the link neither, right?
 Quote

Status: offline

Turias

Forum User
Full Member
Registered: 10/20/03
Posts: 807
Quote by geKow: arghh.. you are right Oops!

I go back into my corner
(don't mess with a coder)


Mr. Green

Don't worry. PHP takes some getting used to, as does GeekLog's method of choosing when to set variables and whether the variable should be set as 'blank' or its actual value.

It would be nice if GeekLog always set all of the variables to their correct values and then let the themes decide whether or not to display them. Unfortunately, that would take a lot of work to implement and would mean more PHP/JavaScript in the theme files, making these (currently simple) files much more complex.
 Quote

Status: offline

Turias

Forum User
Full Member
Registered: 10/20/03
Posts: 807
Quote by geKow:edited a little later:
But if the site or usersettings are set to show no icons... you won't need the link neither, right?


Normally that's true, since, by default, GeekLog only uses the link to hold the topic icon.

But if a theme writer wants to use that url for something else, they can only get at it when the icon is going to be displayed, even if they want to display it for another purpose.

Thus, the theme writer is forced to ensure that the url variable will be valid whether or not the icons are going to be displayed.
 Quote

Status: offline

geKow

Forum User
Full Member
Registered: 01/12/03
Posts: 445
Yes, I understand and it makes sense even to me.

would you mind to give me a more detailled view of your last suggestion? (the one with the topic url) in other words: a code snippet?

geKow
 Quote

Status: offline

Turias

Forum User
Full Member
Registered: 10/20/03
Posts: 807
All that I mean is that the new variable that you always want to use must be outside of that if block. Compare my previous code to this new one, which is updated for using the url:

Text Formatted Code

$result = DB_query( "SELECT imageurl,topic FROM {$_TABLES['topics']} WHERE tid = '{$A['tid']}'" );
$T = DB_fetchArray( $result );

$topicname = htmlspecialchars( stripslashes( $T['topic'] ));
$article->set_var( 'story_topic_name_hack', $topicname );
$topicurl = $_CONF['site_url'] . '/index.php?topic=' . $A['tid'];
$article->set_var('story_topic_url_hack', $topicurl);

if ( $_USER['noicons'] != 1 AND $A['show_topic_icon'] == 1 )
{
    if( !empty( $T['imageurl'] ))
    {
        if( isset( $_THEME_URL ))
        {
            $imagebase = $_THEME_URL;
        }
        else
        {
            $imagebase = $_CONF['site_url'];
        }
        $topicimage = '<img align="' . $_CONF['article_image_align']
                . '" src="' . $imagebase . $T['imageurl'] . '" alt="'
                . $topicname . '" title="' . $topicname . '" border="0">';
        $article->set_var( 'story_anchortag_and_image', '<a href="'
                . $topicurl . '">' . $topicimage . '</a>' );
        $article->set_var( 'story_topic_image', $topicimage );
    }
    $article->set_var( 'story_topic_id', $A['tid'] );
    $article->set_var( 'story_topic_name', $topicname );
    $article->set_var( 'story_topic_url', $topicurl );
}

 


Now the URL can always be used, even if the topic icon is not going to be displayed.
 Quote

Status: offline

geKow

Forum User
Full Member
Registered: 01/12/03
Posts: 445
Oops! I nearly missed that posting.
Thank you very much
 Quote

Status: offline

Turias

Forum User
Full Member
Registered: 10/20/03
Posts: 807
No problem. Big Grin
 Quote

All times are EDT. The time is now 10:07 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content