1.
This Tutorial will take you through the steps to modify a 1.6 package so that it will allow you to post both Articles AND Pages by Category.
Example: Create a category called
Environment and post pages under it called
Saving Water and
Weekend Recycling and the URLs to them would be:
-
http://mysite.com/environment/saving-water-
http://mysite.com/environment/weekend-recycling2. Here is a generic function that can be used to display article leads for Articles, or Pages, or Both. It was done for 1.6 but it will work equally well with 1.7.
Just copy the complete script below into a new PHP file called
content_leads.php (or whatever you like) and save it.
<?php
/* -----------------------------------------------------------------------
content_leads.php
By: keyrocks, Oct.17.07
-----------------------------------------------------------------------*/
// CONTENT LEADS: ARTICLES or PAGES or BOTH
function content_leads($start, $size) {
# THREE QUERY OPTIONS - Only one can be active. Content is ordered by Date in descending order (latest to oldest)
# 1. SELECT PUBLISHED ARTICLES
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 ORDER BY date DESC LIMIT $start, $size";
# 2. SELECT PUBLISHED PAGES
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 3 AND published = 1 ORDER BY date DESC LIMIT $start, $size";
# 3. SELECT PUBLISHED ARTICLES and PAGES
$query = "SELECT * FROM ".db('prefix')."articles WHERE position IN (1,3) AND published = 1 ORDER BY date DESC LIMIT $start, $size";
$result = mysql_query($query);
if (!$result || !mysql_num_rows($result)) {
echo '<ul><li>'.l('no_articles').'</li></ul>';
} else {
$home = l('home_sef');
while ($r = mysql_fetch_array($result)) {
$text = $r['text']; // new string
$date = date(s('date_format'), strtotime($r['date']));
$categorySEF = find_cat_sef($r['category']);
$title = $r['category'] == 0 ? $home : retrieve('name', 'categories', 'seftitle', $categorySEF);
# SHOW CONTENT LEADS: title, date published, lead text, and "read more" link.
echo '<p class="leads"><strong>'.$r['title'].'</strong> - '.$date.'</p>'.substr($text,0,100).'...'
.'<a href="'.db('website').$categorySEF.'/'.$r['seftitle'].'/" title="Read more about '.$title.'"> read more</a></p>';
}}}
?>
Purpose: - Display the latest content as short leads complete with: title, date-line, intro lead-in text, and a "read more" link.
Location: - Locate this file in a mods folder in your site root.
Inclusion: - Include this file wherever you are including snews.php by inserting:
include ('mods/content_leads.php');Options: - Three Query options are provided. Only one can be active.
1. selects and displays only published Articles.
2. selects and displays only published Pages.
3. selects and displays both published Articles and Pages.
You can replicate the function, re-name it, use one for articles only and one for pages only.
Display: - Content leads are displayed within the template (index.php) file by inserting (where you want it in the template):
<ul> <?php content_leads(0,3); ?> </ul>How Many: - The number values in brackets determine which of the latest entries will be the 1st one shown, followed by the number of
entries to be shown. By default: lead_articles(
0,3); starts with 1st, shows 3.
Lead Length: - The amount of "content lead" text displayed is determined by the number of characters set as the SECOND number in brackets near the end of the first string - ($text,0,1
00) under # SHOW CONTENT LEADS: - in the function above. In this case it is 100 characters. Increase or decrease as needed.
Styling: - You can add css styles to the # SHOW CONTENT LEADS: string as required, ensuring that the style declarations are included in stylesheets for all templates.