Welcome to Geeklog, Anonymous Monday, November 25 2024 @ 11:56 am EST
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
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
8
13
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
delete that entire if block and replace it with:
$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.
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.
12
18
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.
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.
12
12
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:
(where the class is just my idea how to style that)
anyway, thanks for the improvement
geKow
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
11
18
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
in my code. That will guarantee that it is set no matter what the story or user preferences.
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.
12
15
Quote
Status: offline
Turias
Forum User
Full Member
Registered: 10/20/03
Posts: 807
Quote by geKow: arghh.. you are right
I go back into my corner
(don't mess with a coder)
I go back into my corner
(don't mess with a coder)
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.
12
12
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?
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.
12
10
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:
$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.
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.
15
16
Quote
All times are EST. The time is now 11:56 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