Welcome, Guest. Please login or register.
Did you miss your activation email?
May 26, 2012, 12:39:55 AM

Login with username, password and session length
Search:     Advanced search
Wollen Sie dem WebsiteBaker Team beitreten?
Nähere Informationen finden Sie unter hier und auf unserer neuen Webseite.
155533 Posts in 21713 Topics by 7738 Members
Latest Member: Pattieardathfe
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Changes to URL to display full news  (Read 463 times)
fboehlandt

Offline Offline

Posts: 69


« on: September 30, 2009, 09:04:22 PM »

Hi everyone,
I have the following bit of code to display news items. However, I don't know what I have to alter in order to display the 'long' news. >read more< should take me to a news page where the article is displayed in full. It works fine when I use the news module from WB but I cannot implement it myself in the index.php file. Can anyone help? I have very little PHP/SQL background...thanks

Code:
<div class="post">
                    <?php
                    
// Specify the Group(id) you want to read the news from or 0 for all groups
                    
$group 0;       

                    
// Specify number of newsitems                       
                    
$limit=3;

                    
// Specify read more text
                    
$readmore "Read more";             

                    
// Query for obtaining stuff from a group
                    
$query "SELECT * FROM ".TABLE_PREFIX."mod_news_posts WHERE group_id = $group and active = 1 ORDER BY position DESC LIMIT 0, 10;";

                    
// Query for all groups ;)
                    
if ($group<) {
                      
$query "SELECT * FROM ".TABLE_PREFIX."mod_news_posts WHERE active = 1 ORDER BY position DESC LIMIT 0, 10;";
                    }

                    
// No changes needed here, maybe for output!

                    
global $database;

                    
$result $database->query($query);
                    
$total $result->numRows();      // how many items are there?

                    
if ($total>1) {                   // at least 2 needed for 2 news items
                      
$data1 $result->fetchRow() ;   // get left item
                      
$data2 $result->fetchRow() ;  // get right item
                          
$data3 $result->fetchRow() ;

                      echo 
'<h4>'.$data1['title'].'</h4>
                        <p>'
.$data1['content_short'].'</p>
                        <ul class="controls">
                            <li><a href="'
.WB_URL.PAGES_DIRECTORY.$data1['link'].PAGE_EXTENSION.'" class="more">'.$readmore.'</a></li>
                        </ul>
                        <br />'
;
                      
                      echo 
'<h4>'.$data2['title'].'</h4>
                        <p>'
.$data2['content_short'].'</p>
                        <ul class="controls">
                            <li><a href="'
.WB_URL.PAGES_DIRECTORY.$data2['link'].PAGE_EXTENSION.'" class="more">'.$readmore.'</a></li>
                        </ul>
                        <br />'
;
                                            
                      echo 
'<h4>'.$data3['title'].'</h4>
                        <p>'
.$data3['content_short'].'</p>
                        <ul class="controls">
                            <li><a href="'
.WB_URL.PAGES_DIRECTORY.$data3['link'].PAGE_EXTENSION.'" class="more">'.$readmore.'</a></li>
                        </ul>
                        <br />'
;
                    }
                    else {
                      echo 
'<span style="font-size: 12px; display: block; font-weight: bold; border-bottom: 1px solid;">No News yet ...</span>';
                    }
                    
?>

                    </div>
Logged
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #1 on: September 30, 2009, 09:25:50 PM »

Hello,
thre is a whole Module with the name "AnyNews" provided by Christian (doc).

If you don't want to use it, the code will help anyway.

Just test it:
http://addons.websitebaker.org/pages/modules/code-snippets.php

Kind regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
fboehlandt

Offline Offline

Posts: 69


« Reply #2 on: September 30, 2009, 10:21:08 PM »

Thanks for the reply,
I have implemented the snippet and I can see it is easy to use. The 'short' news/posts are displayed as intended. However, >read more< does not take me to the full article. Is there a dummies guide to this snippet?
Logged
Stefek
WebsiteBaker Org e.V.

Offline Offline

Posts: 4884



« Reply #3 on: September 30, 2009, 10:37:28 PM »

As far as I know, you'll find it just inside of the zip file.
Should be in at least 2 languages.

Kind regards,
Stefek
Logged

"In a time of universal deceit, telling the truth becomes a revolutionary act."
- George Orwell, Nineteen eighty-four (1984)
fboehlandt

Offline Offline

Posts: 69


« Reply #4 on: September 30, 2009, 11:05:37 PM »

In order to clarify my problem I briefly describe the steps I have taken:
1. Using the modify dialogue in WB, I added 5 posts and 2 groups to my homepage. I have two types of posts/news that I would like to display in different blocks of my homepage
2. I downloaded the code snippet, packed it as .zip-file and uploaded the module
3. I copied the following code in the appropriate content area in my index.php file:

Code:
<?php
if (function_exists('displayNewsItems')) {
displayNewsItems();
}
?>

The news are displayed as intended. I have not bothered with the details yet(I understand that I must specify the query first to call news from a particular group). However, at the moment I cannot figure out why the full news are not being displayed when I test the link >read more<. When using the build-in WB news module, the 'long' news/post version would pop up on a child page called "news" (which I did not have to specify) when I prompted the >read more< link. What steps am I missing here? Can I still specify posts using WB and call upon them via the displayNewsItems function?
Logged
erpe

Offline Offline

Posts: 2077


WWW
« Reply #5 on: October 01, 2009, 08:41:13 AM »

Hi

is there a link available to see the site?

rgds

erpe
Logged

Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!