Posted on: 01/08/04 10:38am
By: spiffin
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
Re:Topic name in story title
Posted on: 01/08/04 11:04am
By: Turias
Here's a quick hack to do what you want:
Open up lib-common.php,
in COM_article, find
if( $_USER['noicons'] != 1 AND $A['show_topic_icon'] == 1 )
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.
Re:Topic name in story title
Posted on: 01/08/04 12:35pm
By: spiffin
Thanks very much for your help.
That worked a treat.
spiffin
Re:Topic name in story title
Posted on: 01/08/04 03:25pm
By: geKow
I did it this way:
in storytext.thtml and featuredstorytext.thtml I replaced
{story_anchortag_and_image}
with
{story_topic_name}
geKow
Re:Topic name in story title
Posted on: 01/08/04 03:28pm
By: Turias
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.
Re:Topic name in story title
Posted on: 01/08/04 03:42pm
By: Turias
There, that should fix the problems it had before. Make sure you update your code, spiffin.
Re:Topic name in story title
Posted on: 01/08/04 04:54pm
By: geKow
ok, I (PHP idiot) followed your way and it works. I have only one improvement: If you want the category be a link:
<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
Re:Topic name in story title
Posted on: 01/08/04 05:06pm
By: Turias
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
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.
Re:Topic name in story title
Posted on: 01/08/04 05:27pm
By: geKow
arghh.. you are right
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?
Re:Topic name in story title
Posted on: 01/08/04 05:37pm
By: Turias
[QUOTE BY= geKow] arghh.. you are right
I go back into my corner
(don't mess with a coder) [/QUOTE]
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.
Re:Topic name in story title
Posted on: 01/08/04 06:01pm
By: Turias
[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?[/QUOTE]
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.
Re:Topic name in story title
Posted on: 01/08/04 06:33pm
By: geKow
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
Re:Topic name in story title
Posted on: 01/08/04 09:11pm
By: Turias
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.
Re:Topic name in story title
Posted on: 01/14/04 07:10pm
By: geKow
I nearly missed that posting.
Thank you very much
Re:Topic name in story title
Posted on: 01/15/04 09:37am
By: Turias
No problem.