Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [MOD] More articles insert box (sNews 1.5)  (Read 6048 times)

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] More articles insert box (sNews 1.5)
« on: November 02, 2006, 05:28:27 pm »

This mod produces an insert into/onto the output of center() with a list of other articles in the current category, linked for easy access.
Added the category name to be prepended to the title you enter.

Copy the following NEW code, and paste into snews.php
Code: [Select]
//ARTICLES IN THIS CATEGORY
function more_articles($limit,$styleit,$classname,$idname,$title,$hsize){
$link='<a href="'.db('website');
$categorySEF = get_id('category');
$articleSEF = get_id('article');
if (!empty($categorySEF)){
$cat_query = "SELECT * FROM ".db('prefix')."categories WHERE seftitle = '$categorySEF' ";
$cat_result = mysql_query($cat_query);
$f = mysql_fetch_array($cat_result);
$catid= $f['id'];
$catName= $f['name'];
if ($catid >0) {
$art_query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = '1' ";
$query = $art_query." AND category = $catid ORDER BY date DESC LIMIT $limit";
$result = mysql_query($query);
if (mysql_num_rows($result)>1){
if ($styleit == 1){ $echo ="<div ";
if (!empty($classname)){ $echo.="class=\"$classname\" ";}
if (!empty($idname)){ $echo.= "id=\"$idname\" ";}
$echo.=">"; }
if (!empty($hsize)){$hstart = "<";$hend ="</";$hclose=">";}
if (!empty($title)){$echo.= $hstart.$hsize.$hclose.$catName." ".$title.$hend.$hsize.$hclose."<ul>";}
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = '1'  AND category = $catid ORDER BY date DESC LIMIT $limit";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
if ($r['seftitle']!=$articleSEF){
$echo.= "<li>".$link.$f['seftitle'].'/'.$r['seftitle'].'/" title="'.$r['title'].'">'.$r['title'].'</a></li>';
}}
if ($styleit == 1){ $echo.= "</ul></div>" ;}}
}}echo $echo;}
usage:-
I place the more_articles() function just above the center() function in index.php.
Quote
<?php more_articles(6,1,'box','insert','Other Articles',h2) ?>
<?php center(); ?>
Explanation.
Quote
more_articles( [articleLimit] , [wrap the output] , '[class]' , '[id]' , '[title for insert]' , [<h> size] )

like this
more_articles(6,1, 'box','insert','Other Articles',h2)

-show another 6 available articles in this category.
-wrap the output in <div>, to apply styles
- use class="box"
- use id="insert"
- use  Other Articles  as a header inside the insert
- set the heading tag to <h2>
This will NOT show a list of other articles on the Home page
This will NOT display if there is only one article in a category

sample style:-
Code: [Select]
#insert {
background-color:#dfe;padding:.3em;
margin-top:1em;
height: auto;
width: 30%;
float: right;
}
.box {
border: 1px solid #ccc;
padding: 1em;
margin: 0 0 1em 0;
}
Sample screenshot


Quote
Updates
slight layout error produced <ul><Hx> instead of </Hx><ul> now corrected.
Tidied code (now using  !isempty instead of issett && != null).
Output is now in form of  
<div class="" id=""><h>[article category]+[your title]</h><ul>
<li> </li>
<li> </li>
...etc
</ul></div>


« Last Edit: September 24, 2007, 01:21:45 am by philmoz »
Logged
Of all the things I have lost, it is my mind that I miss the most.

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] More articles insert box (sNews 1.5)
« Reply #1 on: November 03, 2006, 11:31:26 am »

it is also possible to use this  as another section of the site, by placing it after a </div> and before the next <div> in the index.php (based on the default that came with RC3.
for eg, section of the default index.php
Code: [Select]
<div id="right">
<div class="box">
<h2>Categories:</h2>
<ul>
<?php categories(); ?>
</ul>
</div>
<?php more_articles(6,1,'box','','Articles:',3?>
<div class="box">
<h2>New comments:</h2>
<ul>
<?php new_comments(530); ?>
</ul>
</div>
using the class .box above, results in this:-
« Last Edit: September 24, 2007, 01:22:23 am by philmoz »
Logged
Of all the things I have lost, it is my mind that I miss the most.

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] More articles insert box (sNews 1.5)
« Reply #2 on: November 03, 2006, 01:04:52 pm »

added the category name to be prepended to the title you enter. results in something like...


Adjusted code in OP
Logged
Of all the things I have lost, it is my mind that I miss the most.

Lucian

  • Newbie
  • *
  • Karma: 0
  • Posts: 7
    • http://www.editiaspeciala.com
[MOD] More articles insert box (sNews 1.5)
« Reply #3 on: November 03, 2006, 02:23:09 pm »

very nice philmoz, I have just used it  - I had to change it a little bit to create <li> articles and not use <br/>. But it works great, thanks
« Last Edit: September 24, 2007, 01:22:46 am by philmoz »
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] More articles insert box (sNews 1.5)
« Reply #4 on: November 04, 2006, 03:44:47 am »

Quote from: lbordea
very nice philmoz, I have just used it  - I had to change it a little bit to create <li> articles and not use <br/>. But it works great, thanks
Ah... good point.

so, should I have made the output

<div id= class= ><H></H><ul><li>
links
</li></ul></div>


Did it anyway, plus a few other tweaks. OP changed to reflect them
« Last Edit: September 24, 2007, 01:23:00 am by philmoz »
Logged
Of all the things I have lost, it is my mind that I miss the most.

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
[MOD] More articles insert box (sNews 1.5)
« Reply #5 on: December 06, 2006, 08:02:20 pm »

phil, this is great mod, mate :)

*sorry, but I haven't noticed this mod before(?)... right now I'm testing some of the mods before moving them to their appropriate subforum, and your work came like a revelation to me :D *
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] More articles insert box (sNews 1.5)
« Reply #6 on: December 19, 2006, 12:27:25 am »

Quote from: Mika
*sorry, but I haven't noticed this mod before(?)... right now I'm testing some of the mods before moving them to their appropriate subforum, and your work came like a revelation to me :D *
Wondered what you meant by revelation... ;)

... but I think I spotted it in use on Ni5Ni6.com :D

swings and merry-go-rounds  :cool:
Logged
Of all the things I have lost, it is my mind that I miss the most.

ketut

  • Full Member
  • ***
  • Karma: 0
  • Posts: 115
    • Book Bali Hotels
[MOD] More articles insert box (sNews 1.5)
« Reply #7 on: December 19, 2006, 02:48:55 am »

thanks for your great mod philmoz :cool:
But how move title <H2> before <UL>, I got like this :

Quote
<div class="box" id="insert" ><ul><h4>Hotels Articles:</h4><li><a href="http://www.nusa-penida.com/hotels/mushroom-bungalows/" title="Mushroom Bungalows">Mushroom Bungalows</a></li></ul></div>
« Last Edit: September 24, 2007, 01:23:22 am by philmoz »
Logged

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
[MOD] More articles insert box (sNews 1.5)
« Reply #8 on: December 19, 2006, 07:29:26 am »

nice one phil,
i am working on same kind of mod on my site for some time,
on my website the mod output dynamic links list in the home page or article lists on categories..

on this mod it will auto list the title, description, and the list of the current articles with-in a <ul>, all parts are <li>
and when on home it will output the pages function :)
it is posible to change the line after the else to any thing you want, like ads, images, text, other functions etc..

that the code im using:

Quote
function dyn_nav() {
echo '<ul>';
   $link = '<a href="'.db('website');
   $art_query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = '1'";
   $query = $art_query." AND category = 0 ORDER BY date DESC";
   $result = mysql_query($query);
   $categorySEF = get_id('category');
   $home = s('home_sef');
   $categ = retrieve('id', 'categories', 'seftitle', $categorySEF);
   $query = "SELECT * FROM " .db('prefix'). "categories WHERE published = 'YES' and id = '$categ'";
    $result = mysql_query($query);
   if ($c = mysql_fetch_array($result)) {
      ///// -----  category title and link, just un/comment the line below to switch on/off ----- //////////
      echo '<li><a href="'.db('website').$c['seftitle'].'/" title="'.$c['description'].'">'.$c['name'].'</a>';
      ///// -----  category description ----- /////////
     echo ' | '.$c['description'].'</li>';
      
      $catid = $c['id'];
      $query = $art_query." AND category = $catid ORDER BY id ASC";
      $result = mysql_query($query);
      while ($r = mysql_fetch_array($result)) {
         echo '<li>' .$link.$c['seftitle'].'/'.$r['seftitle'].'/" title="'.$r['title'].'">'.$r['title'].'</a></li>';
      }   
   }   
   else {
   ///// -----  alt content ( links or any content ) for the home page ----- //////////
   echo  pages();
   }
echo '</ul>';
}
for plain UL,
just add <? dyn_nav(); ?> any where in the index.

or,
toss it in any container element, style it as any list.

style ---
#dynav { }
   #dynav ul { }
   #dynav li { }
   #dynav li a { }

html ---
<div id="dynav">
<? dyn_nav(); ?>
</div>
« Last Edit: September 24, 2007, 01:23:40 am by philmoz »
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] More articles insert box (sNews 1.5)
« Reply #9 on: December 19, 2006, 09:56:15 pm »

Quote from: ketut
thanks for your great mod philmoz :cool:
But how move title <H2> before <UL>, I got like this :

Quote
<div class="box" id="insert" ><ul><h4>Hotels Articles:</h4><li><a href="http://www.nusa-penida.com/hotels/mushroom-bungalows/" title="Mushroom Bungalows">Mushroom Bungalows</a></li></ul></div>
Whoops.. my bad. Original post updated..

Need to alter 2 lines
Quote
$echo.="><ul>";    }
cut the <ul> from that part -- make sure quotes and semi-colon remain.
Then add  ."<ul>" to this line before the semi colon
Quote
if (!empty($title)){$echo.= $hstart.$hsize.$hclose.$catName." ".$title.$hend.$hsize.$hclose."<ul>";
« Last Edit: September 24, 2007, 01:24:19 am by philmoz »
Logged
Of all the things I have lost, it is my mind that I miss the most.

ketut

  • Full Member
  • ***
  • Karma: 0
  • Posts: 115
    • Book Bali Hotels
[MOD] More articles insert box (sNews 1.5)
« Reply #10 on: December 20, 2006, 02:29:36 am »

thank your very much philmoz, work well now :cool:

Success

  • Newbie
  • *
  • Karma: 0
  • Posts: 8
[MOD] More articles insert box (sNews 1.5)
« Reply #11 on: December 27, 2006, 06:50:25 pm »

Instead of "Category Other Articles", how to edit the code to display the Title as "Other articles in CATEGORY-NAME" where the category name is a link to that category?
Logged

philmoz

  • High flyer
  • ULTIMATE member
  • ******
  • Karma: 161
  • Posts: 1988
    • fiddle 'n fly
[MOD] More articles insert box (sNews 1.5)
« Reply #12 on: May 05, 2007, 04:04:38 pm »

Quote from: Success
Instead of "Category Other Articles", how to edit the code to display the Title as "Other articles in CATEGORY-NAME" where the category name is a link to that category?
A bit late... sorry about that...

find this
Quote
if (!empty($title)){$echo.= $hstart.$hsize.$hclose.$catName." ".$title.$hend.$hsize.$hclose."<ul>";}
and swap the blue bits.
« Last Edit: September 24, 2007, 01:24:50 am by philmoz »
Logged
Of all the things I have lost, it is my mind that I miss the most.