Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Latest Articles In Tab thingy  (Read 10976 times)

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Latest Articles In Tab thingy
« on: December 24, 2009, 07:54:44 pm »

Not sure what to call this but it is based on this thread: http://snewscms.com/forum/index.php?topic=8851.0

I am using jQuery for this, not the dynamic drive script.  Feel free to change it alter it etc. Partially based on http://snewscms.com/forum/index.php?topic=5780.0




**** NOTE ****
I only testing this out on my machine using a base install of 1.6.  If it doesn't work or not supposed to do x, then it is up to you to work on it and add your edits here

0. Backup
1. There was a mod somewhere that allowed the number id of the categories to be shown in the admin... find it and add it, or if you know the cat ID's then continue!
2. I have this after the include(snews.php) in the index.php:
Code: [Select]
<?php
function get_featured_articles$catArray$txtLimit ) {
if (!is_array($catArray)) return;
$catCount count($catArray);
$cats implode(','$catArray);
$query 'SELECT
category, title, seftitle as artSEF, text
FROM '
.db('prefix').'articles
WHERE position = 1 
AND published = 1 
AND category IN('
$cats .')
ORDER BY date DESC 
LIMIT '
$catCount;
$result mysql_query($query);
$c = array();
while ($r mysql_fetch_assoc($result)){
$r['catSEF'] = find_cat_sef($r['category']);
$r['text'] = substr($r['text'], 0$txtLimit).'...';
$c[] = $r;
}
if (empty($c)) $c['error'] = l('no_articles');
return $c;
}

function 
featured_articles$catArray$txtLimit 200 ) {
$c get_featured_articles$catArray$txtLimit );
if (isset($c['error'])) {
echo '<p>'.$c['error'].'</p>'
} else {
foreach ($c as $k=>$v){
echo '
<div id="'
$v['artSEF'] .'_tab">
<h4><a href="'
.db('website').$v['catSEF'].'/'.$v['artSEF'].'/">'.$v['title'].'</a></h4>
<p class="latest-text">'
$v['text'] .'</p>
</div>'
;
}

   // If the user doesn't have Javascript enabled....
echo "
<script type=\"text/javascript\">
document.write('"
;
echo '<ul class="tabs">';
$count 1;
foreach ($c as $k=>$v){
echo '<li><a href="#'$v['artSEF'] .'_tab">'$count .'</a></li>';
$count++;
}
echo '</ul>';
echo "');</script>";
}
}

?>


3. Before the closing </head>
Code: [Select]
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" ></script>
<style type="text/css">
.ui-tabs .ui-tabs-hide {
display: none;
}
.ui-state-active a {
/* add your active css here */
}
#featured ul {
display: block;
border-top: 1px solid #ccc;
}
#featured ul li {
display: inline;
padding-right: 10px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$("#featured").tabs();
});
</script>

4. Somewhere, anywhere in the template: (the cat numbers here are at random.. but need to be in an array!!!)
Code: [Select]
<div id="featured">
<h3>Featured Articles</h3>
<?php featured_articles( array( 03) ); ?>
</div>


**** NOTE ****
I only testing this out on my machine using a base install of 1.6.  If it doesn't work or not supposed to do x, then it is up to you to work on it and add your edits here
« Last Edit: December 25, 2009, 02:31:47 am by nukpana »
Logged

princess

  • Newbie
  • *
  • Karma: 0
  • Posts: 21
Re: Latest Articles In Tab thingy
« Reply #1 on: December 26, 2009, 07:04:41 pm »

Thank you, Professor
This method does not work great with me
When I add a custom code to the index.php file and in snews.php does not show anything to the home page
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: Latest Articles In Tab thingy
« Reply #2 on: December 27, 2009, 03:02:47 am »

Nothing goes in snews.php per this how to.  It seems you may have copied the <?php ?> tags.
Logged

princess

  • Newbie
  • *
  • Karma: 0
  • Posts: 21
Re: Latest Articles In Tab thingy
« Reply #3 on: January 03, 2010, 08:31:50 pm »

I think it can not be put this code in the file index.php
I put it in the last of snews.php
but not working
Please I want to explain better if it was possible, I am new with you and sorry for the inconvenience continued
Thanks
Logged

nukpana

  • Hero Member
  • *****
  • Karma: 71
  • Posts: 663
Re: Latest Articles In Tab thingy
« Reply #4 on: January 03, 2010, 10:06:02 pm »

Not sure where you are going wrong.  I just installed a fresh 1.6 and follwed these directions.  My index.php looks like this:

Code: [Select]
<?php session_start(); include('snews.php'); ?>
<?php
function get_featured_articles$catArray$txtLimit ) {
if (!is_array($catArray)) return;
$catCount count($catArray);
$cats implode(','$catArray);
$query 'SELECT
category, title, seftitle as artSEF, text
FROM '
.db('prefix').'articles
WHERE position = 1 
AND published = 1 
AND category IN('
$cats .')
ORDER BY date DESC 
LIMIT '
$catCount;
$result mysql_query($query);
$c = array();
while ($r mysql_fetch_assoc($result)){
$r['catSEF'] = find_cat_sef($r['category']);
$r['text'] = substr($r['text'], 0$txtLimit).'...';
$c[] = $r;
}
if (empty($c)) $c['error'] = l('no_articles');
return $c;
}

function 
featured_articles$catArray$txtLimit 200 ) {
$c get_featured_articles$catArray$txtLimit );
if (isset($c['error'])) {
echo '<p>'.$c['error'].'</p>'
} else {
foreach ($c as $k=>$v){
echo '
<div id="'
$v['artSEF'] .'_tab">
<h4><a href="'
.db('website').$v['catSEF'].'/'.$v['artSEF'].'/">'.$v['title'].'</a></h4>
<p class="latest-text">'
$v['text'] .'</p>
</div>'
;
}

   // If the user doesn't have Javascript enabled....
echo "
<script type=\"text/javascript\">
document.write('"
;
echo '<ul class="tabs">';
$count 1;
foreach ($c as $k=>$v){
echo '<li><a href="#'$v['artSEF'] .'_tab">'$count .'</a></li>';
$count++;
}
echo '</ul>';
echo "');</script>";
}
}

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<?php title(); ?>

<meta name="Robots" content="index,follow" />

<meta name="Generator" content="sNews 1.6" />

<link rel="stylesheet" type="text/css" href="style.css" media="screen" />

<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss-articles/" />

<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss-pages/" />

<link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="rss-comments/" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" ></script>
<style type="text/css">
.ui-tabs .ui-tabs-hide {
display: none;
}
.ui-state-active a {
/* add your active css here */
}
#featured ul {
display: block;
border-top: 1px solid #ccc;
}
#featured ul li {
display: inline;
padding-right: 10px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$("#featured").tabs();
});
</script>

</head>

<body>

<div class="wrap">

<div id="logo">

<h1><?php echo s('website_title'); ?></h1>

</div>



<ul id="menu">

<?php pages(); ?>

</ul>



<div id="subheader">

<div id="breadcrumbs">

<?php breadcrumbs(); ?>

</div>



<div id="search">

<?php searchform(); ?>

</div>

</div>



<div id="left">

<h3>Categories:</h3>

<ul>

<?php categories(); ?>

</ul>



<h3>New Articles:</h3>

<ul>

<?php menu_articles(0,3); ?>

</ul>



<h3>New comments:</h3>

<ul>

<?php new_comments(530); ?>

</ul>


<div id="featured">
<h3>Featured Articles</h3>
<?php featured_articles( array( 01) ); ?>
</div>


<?php extra(); ?>

</div>



<div id="right">

<?php center(); ?>

</div>



<div id="footer">

<ul id="rss">

<?php rss_links(); ?>

</ul>

<p>Barbecued by <a href="http://snewscms.com/" title="Single file CMS">sNews</a> &middot; <?php login_link(); ?></p>

</div>

</div>

</body>

</html>
Logged

princess

  • Newbie
  • *
  • Karma: 0
  • Posts: 21
Re: Latest Articles In Tab thingy
« Reply #5 on: January 04, 2010, 06:28:55 am »

Thank you very much
The script works great now
But I want to show the attached photo with the subject larger size because the topics included in my site with pictures
Sorry for the inconvenience once again Professor nukpana
Logged