Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: need a help to display article which is in category on homepage  (Read 893 times)

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
need a help to display article which is in category on homepage
« on: February 10, 2012, 04:39:59 AM »

id ??? ???
« Last Edit: April 15, 2012, 05:15:39 PM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: need a help to display article which is in category on homepage
« Reply #1 on: February 10, 2012, 05:14:25 PM »

Do you want to display this like a menu list... to display titles as links for articles in a specific category in a separate container within the main content area of your template (index.php)?

If so, then I would create a new function to do this, and insert the new function-tag within the styled container in your index.php file where you want it to be displayed. I am thinking the function would need to retrieve the article titles by category ID then generate them.
« Last Edit: February 14, 2012, 02:31:48 AM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: need a help to display article which is in category on homepage
« Reply #2 on: February 11, 2012, 03:00:44 AM »

 ??? ???
« Last Edit: April 15, 2012, 05:14:18 PM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: need a help to display article which is in category on homepage
« Reply #3 on: February 11, 2012, 09:00:54 AM »

I kept the whole night, trying to create some function for this issue;  look what i did and this function need fixes even if there is no problem in work on it.

Code: [Select]
function get_extra_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 extra_articles( $catArray, $txtLimit = 360 ) {
$c = get_extra_articles( $catArray, $txtLimit );
if (isset($c['error'])) {
echo '<p>'.$c['error'].'</p>';
} else {
foreach ($c as $k=>$v){
echo '
<div id="'. $v['artSEF'] .'_tab">
<div class="title_edited_small_title">
<a href="'.db('website').'index/'.$v['artSEF'].'/" style="text-decoration: none;>

<p align="center">'.$v['title'].'</p>
</a> </div>

<p class="latest-text">'. $v['text'] .'<a href="'.db('website').'category's_name/'.$v['artSEF'].'/">[color=green] Read more[/color]</a></p>

</div>';
}

}
}

but the function works in case if you want to call  (1) article from any category;  i use the following function-name tag in index.php to output the content(article),
Code: [Select]
<?php extra_articles( array( ) ); ?>. now my problem is that this function as i said it calls just for one article from each category; but i want it to display for instance two article from one category.
I made a try to solve;
by using editing the tag call; like this
Code: [Select]
<?php extra_articls( array( 1,2,3,) ); ?>but this php it call for one article from each category, so HOW the function i tried to create to be edited in order to support the process.

what is your opinion mr. key :D
« Last Edit: February 11, 2012, 09:15:40 AM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: need a help to display article which is in category on homepage
« Reply #4 on: February 12, 2012, 07:03:06 AM »

Folks I really need for this function, could some support me, i'll be really glad if some member or admin could solve the problem.
as you see i made the php function  but it needs some additions and may not some lines to be deleted.
the problem according to what i think is in; query select. the query line should be the following:
select by order in categories (first and second article)..
several functions in snews file include order by time or ID, date.
« Last Edit: February 12, 2012, 07:06:23 AM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”

sibas

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 451
    • www.simply4all.net
Logged

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: need a help to display article which is in category on homepage
« Reply #6 on: February 12, 2012, 02:29:48 PM »

try this dude
http://snewscms.com/forum/index.php/topic,4569.0.html

can't works, that mod is for adding new category list; but i am dealing with the other issue which is article in category
the php function i wanted doesn't need to create new table in DB or alter it, i would like to ask a question may lead us to solve the request; how do article shown in categories, I meant what the function snews used to call article which is in DB table and display them within category. if we could answer this question we may find the solution.
now the function i made doesn't include any bug or it works with some other issue. now the point is just how to output two or three articles from cat and display them in index.php but not in php center.
does some has a little bit knowledge about the way we call articles to be shown in cat.
« Last Edit: February 12, 2012, 02:32:43 PM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: need a help to display article which is in category on homepage
« Reply #7 on: February 12, 2012, 08:46:49 PM »

Hi adminphp,
*UPDATE
Here is new Function to display recent articles from category.
Use:
//    $num = Number of articles to display.
//    $catid = The category id you want to display articles from.
//   Function call = <?php recent_articles_from_cat(7,1); ?>

In e.g. it will display 7 recent articles from category id 1.
You can enter any number of articles from any category.

If you need to get articles from few categories you add it like this:

recent_articles_from_cat(7,1);
recent_articles_from_cat(3,2);
recent_articles_from_cat(5,4);

Code: [Select]
1. insert in your index, it will display only on home page,
    if you need it to display elsewhere you can remove or change the if condition.
<?php
$categorySEF get_id('category');
if ($categorySEF=='') {
recent_articles_from_cat(2,1);
}
?>


2. insert in your snews.php
Code: [Select]
<?php
//  Recent articles from category
//  $num = Number of articles to display.
//  $catid = The category id you want to display articles from.
// Function call recent_articles_from_cat(7,1);
function recent_articles_from_cat($num$catid) {
$query "SELECT * FROM ".db('prefix')."articles WHERE category='$catid' and position = 1 AND published = 1 ORDER BY date DESC LIMIT $num";
$result mysql_query($query);
if (!$result || !mysql_num_rows($result)) {
echo '<li>'.l('no_articles').'</li>';
} else {
$home l('home_sef');
while ($r mysql_fetch_array($result)) {
$date date(s('date_format'), strtotime($r['date']));
$title ucfirst($r['title']);
$seftitle $r['seftitle'];
$postCat retrieve('seftitle''categories''id'$r['category']);
$postCat $postCat.'/';
$text stripslashes($r['text']);
$shorten strpos($text'[break]');
echo '<div class="wbox">';
echo '<div class="ttlbox">';
echo '<h3><a href="'.db('website').$postCat.$seftitle.'/" title="'.l('read_more').' - '.$title.'"><strong>'.$title.'</strong></a></h3> ';
echo '<span class="adate">'.l('on').' | '.$date.'</span>';
echo '</div>';
echo '<div class="artbox">';
file_include(str_replace('[break]''',str_replace('&''&amp;'$text)), $shorten);
echo '</div>';
echo '<div class="bck"><a href="'.db('website').$postCat.$seftitle.'/" title="'.l('read_more').' - '.$title.'">'.l('read_more').'</a></div>';
echo '<div class="clearer"> </div>';
echo '</div>';
}
}
}
?>


3. insert styles in css file
Code: [Select]
.wbox{margin:5px 0 10px 0; width:200px;}
.ttlbox h3 {font-size:16px; margin:0px 0; padding:0;}
.adate{font-size:11px; margin:0px 0; padding:0;}
.artbox{margin:0px 0 0 10px;font-size:12px;}
.bck{margin:4px 0;}


I hope this works for you,
awesome Night
« Last Edit: February 13, 2012, 09:12:20 PM by mosh »
Logged

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: need a help to display article which is in category on homepage
« Reply #8 on: February 14, 2012, 01:40:57 AM »

 ??? ???
« Last Edit: April 15, 2012, 05:14:26 PM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: need a help to display article which is in category on homepage
« Reply #9 on: February 14, 2012, 02:29:38 AM »

Hi adminphp,
*UPDATE
Here is new Function to display recent articles from category.

Congratulations Mosh... for taking the challenge and meeting it! +karma from me too.  ;D
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: need a help to display article which is in category on homepage
« Reply #10 on: February 14, 2012, 02:33:06 AM »

+ karma for who can reply my last post .hhh ;D :D ;D
Logged
“Fifty years of programming language research, and we end up with C++?”

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: need a help to display article which is in category on homepage
« Reply #11 on: February 14, 2012, 03:12:51 AM »

come on dudes, i need it. :-[ :-[ :-[
Logged
“Fifty years of programming language research, and we end up with C++?”

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
Re: need a help to display article which is in category on homepage
« Reply #12 on: February 14, 2012, 07:04:21 AM »

@Key @adminphp,
Thank you for the karma :)

@adminphp,
Try this:
Code: [Select]
<?php
//  Recent articles from category
//  $num = Number of articles to display.
//  $catid = The category id you want to display articles from.
// Function call recent_articles_from_cat(7,1);
function recent_articles_from_cat($num$catid) {
$query "SELECT * FROM ".db('prefix')."articles WHERE category='$catid' and position = 1 AND published = 1 ORDER BY date DESC LIMIT $num";
$result mysql_query($query);
if (!$result || !mysql_num_rows($result)) {
echo '<li>'.l('no_articles').'</li>';
} else {
$home l('home_sef');
while ($r mysql_fetch_array($result)) {
$date date(s('date_format'), strtotime($r['date']));
$title ucfirst($r['title']);
$seftitle $r['seftitle'];
$postCat retrieve('seftitle''categories''id'$r['category']);
$postCat $postCat.'/';
$text stripslashes($r['text']);
$shorten strpos($text'[break]');

echo '<div id="'$seftitle .'_tab">';
echo '<div class="title_edited_small_title">';
echo '<a href="'.db('website').$postCat.$seftitle.'/" style="text-decoration: none;"><strong>'.$title.'</strong></a>';
echo '<p align="center">'.$title.'</p>';
echo '</div>';

echo '<p class="latest-text">';
file_include(str_replace('[break]''',str_replace('&''&amp;'$text)), $shorten);
echo ' <a href="'.db('website').$postCat.$seftitle.'/">'.l('read_more').'</a>';
echo '</p>';
echo '</div>';
}
}
}
?>


I Hope this one will make your happy :)

awesome day
« Last Edit: February 14, 2012, 10:42:17 AM by mosh »
Logged

adminphp

  • Full Member
  • ***
  • Karma: 4
  • Posts: 150
  • you must be a great snewser .
Re: need a help to display article which is in category on homepage
« Reply #13 on: February 14, 2012, 10:55:42 PM »

 ??? ???
« Last Edit: April 15, 2012, 04:29:15 PM by adminphp »
Logged
“Fifty years of programming language research, and we end up with C++?”