News:

Wondering if this will always be free?  See why free is better.

Main Menu

Page for each SSI news article

Started by mark7144, March 16, 2009, 11:03:49 AM

Previous topic - Next topic

mark7144

I want my SSI news articles on my home page to have their own separate non-forum pages when clicked on, can someone please help with the code?

This is what Bloc said about my request:

Quote from: Bloc on March 16, 2009, 08:52:17 AM
For that to work you probably need to 1) fetch the info from 'News" using SSI and returned as an array, and 2) make your own links from that info(it would have the topic number in the array), and finally 3) let another SSI function fetch the actual post into your page.

None of these is possible from TP I am afraid, but you might be able to do it from your own pages, by the help of a mod that adds a SSI function fetching single post. I would get the SSI info on topic zzz into xx.php and make the links on xx.php point to yy.php?topic=zzz, then inside yy.php use that single-post SSI to show topicID=zzz.(first post will show then naturally)

mark7144

I'm offering $20 for this.

Can a mod move this to the appropriate board now?

onepiece

I hope you are using 1.1.8.

Firstly, install SSI Topic and Replies mod. Then create a file and include SSI.php at the top. Change url of your current news to the file you have created, passing the id of topic by url. In the file you created, fetch the topic info by ssi_topic() function using the id sent with url. Here is an example:

main.php

<?php

$ssi_layers
= array('main');
$context['page_title'] = 'Main Page';
require(
dirname(__FILE__) . '/SSI.php');

$news = ssi_boardNews(1, 5, 0, 250, 'array');

echo
'
<table width="100%" class="tborder" cellspacing="0" cellpadding="4">
<tr>
<td class="catbg">News</td>
</tr>
<tr>
<td>'
;

foreach (
$news as $topic)
{
echo '
<div>
'
, $topic['icon'], ' <a href="page.php?article=', $topic['id'], '"><strong>', $topic['subject'], '</strong></a>
<div class="smaller">'
, $topic['time'], ' ', $txt[525], ' ', $topic['poster']['link'], '</div>
<div class="post" style="padding: 2ex 0;">'
, $topic['body'], '</div>
</div>'
;

if (!$topic['is_last'])
echo '
<hr style="margin: 2ex 0;" width="100%" />'
;
}

echo
'
</td>
</tr>
</table>'
;

?>


Pay attention to the URL here.

<a href="page.php?article=', $topic['id'], '">

It will be like http://forum.com/page.php?article={topic_id}

page.php

<?php

$ssi_layers
= array('main');
$context['page_title'] = 'View Article';
require(
dirname(__FILE__) . '/SSI.php');

$article_id = !empty($_REQUEST['article']) ? (int) $_REQUEST['article'] : 0;

if (empty(
$article_id))
fatal_error('No article selected!', false);

$article = ssi_topic($article_id, 5, 0, 'array');

if (empty(
$article))
fatal_error('Article does not exist!', false);

echo
'
<table width="100%" class="tborder" cellspacing="0" cellpadding="4">
<tr>
<td class="catbg">News</td>
</tr>
<tr>
<td>
<div>
'
, $article['icon'], ' <a href="page.php?article=', $article['id'], '"><strong>', $article['subject'], '</strong></a>
<div class="smaller">'
, $article['time'], ' ', $txt[525], ' ', $article['poster']['link'], '</div>
<div class="post" style="padding: 2ex 0;">'
, $article['body'], '</div>
</div>'
;

if (!empty(
$article['replies']))
{
echo '
<p><strong>Comments</strong></p>
<hr />'
;

foreach ($article['replies'] as $comment)
echo '
<div class="windowbg2" style="padding: 5px; border: 1px solid #AAA;">
<span style="padding-bottom: 5px; border-bottom: 1px dashed;">Poster: '
, $comment['poster']['link'], '</span>
<p>'
, $comment['body'], '</p>
</div>
<br />'
;
}

echo
'
</td>
</tr>
</table>'
;

?>


It shows replies to topic as comments but you can remove the codes if you don't need them.

I hope it helps you. Feel free to ask questions if there is something unclear.

mark7144

#3
Thank you so much for your help, it works great! I encounted an issue with a blank page but fixed it by doing the following:

Replace:

require(dirname(__FILE__) . 'forum/SSI.php');

With:

require_once('forum/SSI.php');

And put that at the top of the pages before everything.

The only issue now is the pages don't have a title tag, can this be fixed?

onepiece

#4
Yeah, you should have change it to path to your SSI.php file. I suggest using the full path there though, that's better.

Is this issue solved then?

Edit.

Quote from: mark7144 on March 18, 2009, 09:30:20 AM
The only issue now is the pages don't have a title tag, can this be fixed?

They should have, unless you removed $context['page_title'] there.

mark7144

In my header.php for all my pages it has:

<title><? echo $title ?></title>

So anyway I can still have a title tag?

onepiece

If you set the $title for those pages too, you'll have the title. I can't help much about how and where to set it, without seeing the actual code though.

mark7144

#7
Does this help?

Header.php (included on all pages):

<?php
require_once('forum/SSI.php');
$context['aeva_safe_passage'] = true;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Header -->
<head>
<title><? echo $title ?></title>
<meta name="description" content="<? echo $description ? $description : ''; ?>" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="andy murray, murray, andy, tennis, news" />
<meta http-equiv="content-language" content="en-gb" />
<meta name="robots" content="noodp" />
<link media="all" href="/mw.css?3" type="text/css" rel="stylesheet" />
<link rel="shortcut icon" href="/favicon.ico" />
<link rel="alternate" type="application/rss+xml" href="http://feeds.feedburner.com/andy-murray-news" title="Andy Murray News via RSS" />
<? echo $can ?>

<script type="text/javascript" src="/mw.js"></script>
<noscript><link media="all" href="/noscript.css" type="text/css" rel="stylesheet" /></noscript>
</head>
<!-- /Header -->

<body>
<div id="main_container">
<div id="banner2"><div class="banner_text"><a class="banner_click" href="/"></a> <strong><?php date_default_timezone_set ("Europe/London"); echo(date("l, j F Y ")); ?></strong> | <a href="/forum/" class="banner_links">Forum</a> | <a href="/forum/news-12/?wap2" class="banner_links">Mobile</a> | <a href="http://feeds.feedburner.com/andy-murray-news" class="banner_links">RSS Feed</a> | <a href="http://www.facebook.com/pages/MurraysWorld/57207935961" class="banner_links">Facebook</a><br />
<form action="http://www.murraysworld.com/search-results.php" id="cse-search-box">
<input type="hidden" name="cof" value="FORID:11" />
<input type="hidden" name="cx" value="015912399745642733982:zef2tzke_fs" />
<input type="hidden" name="ie" value="UTF-8" />
<input type="text" name="q" class="searchbox" value="Search News..." onFocus="if (value == 'Search News...') { value = ''; }" onBlur="if (value == '') { value = 'Search News...'; }" />
<input name="sa" value="Go" alt="Search" id="searchbutton"  class="searchbutton" title="Search" type="submit">
</form>
</div><div></div></div>

<div id="wrapper_parent">
<? include ('poll/top.php'); ?>


Main.php
<?php
$ssi_layers
= array('main');
$context['page_title'] = 'Main Page';

$news = ssi_boardNews(12
, 5, 0, 250, 'array');


echo
'
<table width="100%" class="tborder" cellspacing="0" cellpadding="4">
  <tr>
     <td class="catbg">News</td>
  </tr>
  <tr>
     <td>'
;

foreach (
$news as $topic)
{
  echo
'
        <div>
           '
, $topic['icon'], ' <a href="page.php?article=', $topic['id'], '"><strong>', $topic['subject'], '</strong></a>
           <div class="smaller">'
, $topic['time'], ' ', $txt[525], ' ', $topic['poster']['link'], '</div>
           <div class="post" style="padding: 2ex 0;">'
, $topic['body'], '</div>
        </div>'
;

  if (!
$topic['is_last'])
     echo
'
        <hr style="margin: 2ex 0;" width="100%" />'
;
}

echo
'
     </td>
  </tr>
</table>'
;

?>


Page.php
<? include('header.php'); ?>
<?php
$_GET
['action'] = 'mw_front';
writeLog(true);
?>


<!-- News   -->
<div id="newswrapper">
<?php
$ssi_layers
= array('main');
$context['page_title'] = 'View Article';

$article_id = !empty($_REQUEST['article']) ? (int) $_REQUEST['article'] : 0;

if (empty(
$article_id))
 
fatal_error('No article selected!', false);

$article = ssi_topic($article_id, 5, 0, 'array');

if (empty(
$article))
 
fatal_error('Article does not exist!', false);

echo
'
<table width="100%" class="tborder" cellspacing="0" cellpadding="4">
  <tr>
     <td class="catbg">News</td>
  </tr>
  <tr>
     <td>
        <div>
           '
, $article['icon'], ' <a href="page.php?article=', $article['id'], '"><strong>', $article['subject'], '</strong></a>
           <div class="smaller">'
, $article['time'], ' ', $txt[525], ' ', $article['poster']['link'], '</div>
           <div class="post" style="padding: 2ex 0;">'
, $article['body'], '</div>
        </div>'
;

if (!empty(
$article['replies']))
{
  echo
'
        <p><strong>Comments</strong></p>
        <hr />'
;

  foreach (
$article['replies'] as $comment)
     echo
'
        <div class="windowbg2" style="padding: 5px; border: 1px solid #AAA;">
           <span style="padding-bottom: 5px; border-bottom: 1px dashed;">Poster: '
, $comment['poster']['link'], '</span>
           <p>'
, $comment['body'], '</p>
        </div>
        <br />'
;
}

echo
'
     </td>
  </tr>
</table>'
;

?>
<div align="right"><b><a href="http://www.murraysworld.com/forum/news-b12.0" rel="nofollow">older news &raquo; </a></b></div>
<br />
<div class="bottom_message">Welcome to the leading Andrew Murray website. This is the central resource for anything Andy Murray related. You can keep up to date with <a class="light" href="/andy-murray-ranking/">Andy Murray ranking</a> in the ATP <a class="light" href="/andy-murray-ranking/">here</a>. Fans often post up their <a class="light" href="/forum/murray-pictures-t412.0.html">Andy Murray pictures</a> taken from the latest ATP tournaments. And for the girls, you might be interested in some photos of <a class="light" href="/forum/andy-murray-message-board/andy-murray-shirtless/">Andy Murray shirtless</a> if you take a look around. Our biggest asset here is our <a class="light" href="/forum/index.php">Andy Murray forum</a>, the <a class="light" href="/forum/andy-murray-message-board/">Andy Murray message board</a> has the biggest community of Murray fans on the net. We realise many people find us from searching <a class="light" href="/andy-murray-girlfriend/">Andy Murray Girlfriend</a> and we would therefore recommend you read her profile <a class="light" href="/andy-murray-girlfriend/">here</a>.</div>

</div>
<!-- /News -->

<? include ('poll/top.php'); ?>
<? include('leftbar.php'); ?>
<? include('rightbar.php'); ?>
<? include('footer.php'); ?>

onepiece

#8
How do you set the title for your other pages?

Edit.

Try this.

Code (Find) Select
<? $description = "Andy Murray tennis website with news, results, schedule, live scores, video, pictures and the largest Andy Murray message board.";?>

Code (Replace) Select
<? $title = 'Some title';
$description = "Andy Murray tennis website with news, results, schedule, live scores, video, pictures and the largest Andy Murray message board.";?>

mark7144

Quote from: Tenma on March 18, 2009, 09:48:07 AM
How do you set the title for your other pages?
<? $title = "Example Title"; ?>

onepiece


mark7144

I know how to set my own titles but that is done manually at the top of each page. But for your nice hack, I need a bit of code to grab the title from the name of the article and dump it there automatically.

For example, I tried this but it failed:

<? $title = $article['subject'] ?>

onepiece

Ah, sorry.

Find:
Quote<? include('header.php'); ?>
<?php
$_GET['action'] = 'mw_front';
writeLog(true);
?>


<!-- News   -->
<div id="newswrapper">
<?php
$ssi_layers = array('main');
$context['page_title'] = 'View Article';

$article_id = !empty($_REQUEST['article']) ? (int) $_REQUEST['article'] : 0;

if (empty($article_id))
   fatal_error('No article selected!', false);

$article = ssi_topic($article_id, 5, 0, 'array');

if (empty($article))
   fatal_error('Article does not exist!', false);

echo '
<table width="100%" class="tborder" cellspacing="0" cellpadding="4">

Replace:
Quote<?php

require_once('forum/SSI.php');

$_GET['action'] = 'mw_front';
writeLog(true);

$ssi_layers = array('main');
$context['page_title'] = 'View Article';

$article_id = !empty($_REQUEST['article']) ? (int) $_REQUEST['article'] : 0;

if (empty($article_id))
   fatal_error('No article selected!', false);

$article = ssi_topic($article_id, 5, 0, 'array');

if (empty($article))
   fatal_error('Article does not exist!', false);

$title = $article['subject'];

include('header.php');

echo '
<div id="newswrapper">
<table width="100%" class="tborder" cellspacing="0" cellpadding="4">

Sorry again. For some reason, it stripped out some single quotes within code and php tags. I've put them inside quotes.

mark7144

Fantastic, that worked!! Thanks :D

Now I just want to check with you...I assume getting SEO urls for these pages is on a different level and would be far too much work, right? I currently use PrettyURLs mod.

onepiece

I have no idea about Pretty URLs, sorry. The best I can suggest is asking the author of the mod.

mark7144

No probs, just wanted to check.

You have been incredible getting this working for me, thank you so much!

mark7144

Oh sorry, one last thing. Is it possible to disable emoticons for the comments?

onepiece

You'll have to modify the mod you've installed.

SSI.php

Code (Find) Select
$row['body'] = parse_bbc($row['body'], $row['smileysEnabled'], $row['ID_MSG']);

// Add this to our messages array


Code (Replace) Select
parsesmileys($row['body']);
$row['body'] = parse_bbc(strip_tags($row['body']), $row['smileysEnabled'], $row['ID_MSG']);

// Add this to our messages array

mark7144

Thanks, that worked :)

If anyone can implement a 'Previous' and 'Next' type PHP page system into the above then I can pay, it's the final thing I need done.

onepiece

To add pagination to ssi_boardNews() function.

SSI.php

Code (Find) Select
// Find the posts.

Code (Replace) Select
global $boardurl;
$limit = count($posts);
$per_page = 2;
$start = !empty($_REQUEST['page']) ? (int) $_REQUEST['page'] : 0;
$page_index = constructPageIndex($boardurl . '/test.php?page=%d', $start, $limit, $per_page, true);

// Find the posts.


Code (Find) Select
LIMIT ' . count($posts),
array(
'post_list' => $posts,


Code (Replace) Select
LIMIT {int:start}, {int:limit}',
array(
'post_list' => $posts,
'start' => $start,
'limit' => $per_page,


Code (Find) Select
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}


Code (Replace) Select
echo '
<hr style="margin: 2ex 0;" width="100%" />';
}

echo $page_index;


If you just want Previous/Next links, use this for $per_page variable.

$page_index = (!empty($start) && $start >= $per_page ? '<a href="' . $boardurl . '/test.php?page=' . ($start - $per_page) . '"><< Previous</a>' . ($start + $per_page < $limit ? ' | ' : '') : '') . ($start + $per_page < $limit ? '<a href="' . $boardurl . '/test.php?page=' . ($start + $per_page) . '">Next >></a>' : '');

Note that you should modify the url for $per_page variable to reflect your file, in both cases.

Advertisement: