TinyPortal

Development => Support => Topic started by: DonaldDasher on October 13, 2008, 02:57:05 PM

Title: Setting font size for php blocks?
Post by: DonaldDasher on October 13, 2008, 02:57:05 PM
If I add a font size to the block then  the php code fails - is there a way to do this?
Title: Re: Setting font size for php blocks?
Post by: G6Cad on October 13, 2008, 03:09:46 PM
Cant help you unless we see the code.
Title: Re: Setting font size for php blocks?
Post by: DonaldDasher on October 13, 2008, 07:20:19 PM
Here's the code, which displays a list of recent articles. It currently displays too large.

global $db_prefix, $scripturl, $user_info;

$query = db_query(
    "SELECT subject, id, date, shortname
     FROM {$db_prefix}tp_articles
     WHERE approved = 1
     ORDER BY date DESC
     LIMIT 10", __FILE__, __LINE__);

while ($row = mysql_fetch_assoc($query))
{
  if(empty($row['shortname'])) $row['shortname'] = $row['id'];

  echo '<a href="' . $scripturl . '?page=' . $row['shortname'] . '">' . $row['subject'] . '</a> ' . timeformat($row['date'], $user_info['time_format']) . '<br />';
}


Title: Re: Setting font size for php blocks?
Post by: IchBin on October 13, 2008, 07:39:10 PM
I don't see anything wrong with that code. How were you changing the font?
echo '<font size="12pt"><a href="' . $scripturl . '?page=' . $row['shortname'] . '">' . $row['subject'] . '</a></font> ' . timeformat($row['date'], $user_info['time_format']) . '<br />';

This should work for changing the title to a font sizee of 12pt.
Title: Re: Setting font size for php blocks?
Post by: Ianedres on October 13, 2008, 09:04:59 PM
Slight variation to IchBin's suggestion- just to use the CSS in the theme...

global $db_prefix, $scripturl, $user_info;

$query = db_query(
    "SELECT subject, id, date, shortname
     FROM {$db_prefix}tp_articles
     WHERE approved = 1
     ORDER BY date DESC
     LIMIT 10", __FILE__, __LINE__);

echo '<div class="smalltext">';

while ($row = mysql_fetch_assoc($query))
{
  if(empty($row['shortname'])) $row['shortname'] = $row['id'];

  echo '<a href="' . $scripturl . '?page=' . $row['shortname'] . '">' . $row['subject'] . '</a> ' . timeformat($row['date'], $user_info['time_format']) . '<br />';
}

echo '</div>';

Title: Re: Setting font size for php blocks?
Post by: DonaldDasher on October 13, 2008, 09:19:17 PM
Thanks guys - what I'm trying to do is match the font (which appears to be bold) with the standard block font and size. Ideally I'd also like the date for each to follow on the line beneath the title.
Title: Re: Setting font size for php blocks?
Post by: DonaldDasher on October 13, 2008, 09:21:30 PM
OK, I'm figuring this out for myself now - is there any way to abbreviate the month to the first three letters?

Also, the time format could do with losing the last three digits (:00)

And the numerical day of the month first if possible ;)
Title: Re: Setting font size for php blocks?
Post by: Ianedres on October 13, 2008, 09:35:55 PM
The date is returned as a Unix timestamp, so you use that to extrapolate a variety of chronological info.

Look at the date function (http://www.php.net/manual/en/function.date.php) and format it through that function:

echo '<a href="' . $scripturl . '?page=' . $row['shortname'] . '">' . $row['subject'] . '</a> (' . date("M n, Y - g:ia", $row['date']) . ')<br />';
Title: Re: Setting font size for php blocks?
Post by: DonaldDasher on October 13, 2008, 09:42:21 PM
Fabulous, many thanks ;)
Title: Re: Setting font size for php blocks?
Post by: G6Cad on October 14, 2008, 12:18:54 PM
Solved then  :up:
Title: Re: Setting font size for php blocks?
Post by: DonaldDasher on October 14, 2008, 12:57:10 PM
Indeed, looking good.