Own CMS System - News articles issues

Hi again PhpFreakz, yet again I have some issues with my PHP part of my website.

A brief summary, I’ve created an simple CMS for my website so that I am able to add news and results faster and easier.
The CMS works great I just have some issues with the finalizing part, so that it also works and looks good with my website.

I have in total 3 issues, I will be stating the easiest first and follow up to the hardest. As I’m sure that many people can help me with some of them and might not be able to solve the difficult ones.

If you head to http://probuyer.dk/demo/index.php#!/Nyheder, you can see my articles I’ve added to my website. I have an issue with the maximum allowed articles on this page. If I were to add several more articles it would just ignore my design and keep on going. I would like to set a maximum of 4 shown articles, how can i do that?

Next up is another fairly easy one. I have - on same page as previous issue - an issue with the articles position. Currently the newest article created is on the bottom, I would like to diverse that so that the top has the newest news and it then goes down to the oldest.

My third issue is a fairly complex one (At least for me) and is also an issue on several other pages. If you notice when you click on one of the news in the article page you get redirected to a new page where you can read the full article, problem is that I would like this “new page” to be opened in the same page as where the articles are. For example if you were to change on the navigation, then you get redirected on the same page but only on the “box” that appears. I would like the same effect from when my readers click on one of my articles, they just get a box with the full article and a “go back button”. How could i possibly do this?

Here are the codes I think are necessary to fix my issues. Let me know if you need anything else and I’ll gladly add those.

For 1st and 2nd issue:
[php]HTML + Some PHP part of index.php

<?php foreach ($articles as $article) { ?>

<?php echo $article['title'] ?>

<?php echo $article[ 'short'] ?>

Artikel skrevet af <?php echo $article[ 'author'] ?> | <?php echo date('j. F o', $article['date']); ?>

<?php } ?>[/php] [b]For 3rd issue:[/b] [i]Full code of article.php[/i] [php]<?php include_once( 'includes/connection.php'); include_once( 'includes/articles.php'); $article=new Article; if (isset($_GET['id'])) { $id = $_GET['id']; $data = $article->fetch_data($id); ?> CMS System

<?php echo $data['title'] ?>

Skrevet af <?php echo $data['author'] ?> den <?php echo date('j. F o', $data['date']); ?>
    <p>
        <?php echo $data[ 'body'] ?>
    </p>

    <a href="index.php">&larr; Back</a>
</div>
<?php } else { header('Location: index.php'); exit(); }	?>[/php]

HTML+PHP part on index.php
[php]






  • Senest nyt - Side 1


    <?php foreach ($articles as $article) { ?>

    <?php echo $article['title'] ?>



    <?php echo $article[ 'short'] ?>


    Artikel skrevet af

    <?php echo $article[ 'author'] ?>
    | <?php echo date('j. F o', $article['date']); ?>



    <?php } ?>
            </div>
            <div class="oldernews"><span class="newsold"><a href="#!/Nyheder_page2"><strong>Ældre artikler ></strong></a></span></span>
            </div>
        </div>
    </div>
    
    [/php]
  • I will try and respond in passing.

    #1. http://papermashup.com/easy-php-pagination/ pagination. You can have as few or many articles as you want.

    #2. Look at your select statement. If you are using an order by clause, modify it the other direction.

    1. I haven’t looked at your site, so I don’t know what you are referring to.

    That tutorial was written five years ago and uses obsolete code.

    Well, you showed various code segments, but, not the code that would be needed to help with some of your issues.

    Let’s start with the number of articles. When you query your database and select a number of articles, you can add “LIMIT 10” to the end of the query. So, 'SELECT * FROM articles" would become 'SELECT * FROM articles LIMIT 10" and it would only grab 10 articles.

    Also, if you wanted the the articles sort in some way, such as newest first, your would add an order of sorting into the query. This is done in this manner: Instead of “SELECT * FROM articles” you would use “SELECT * FROM articles SORTED BY date_field DESCENDING” or some other sort option.

    That should fix up two of your issues. Now, opening “DYNAMIC” content is a bit more tricky.

    So, since PHP is handled SERVER-SIDE only, all of the PHP processing is done on the server. Therefore, if you use a layout and want to open the article inside a

    , you have two ways to handle it. First, you can keep track of the currently view article and just post out the form the itself and make the currently viewed article to be displayed inside the
    . You can keep track of the current article inside a SESSION variable. If the user presses another link to a different article, the page first sets the SESSION variable to point to the new article and displays it. OR, you can use a DYNAMICALLY loaded PHP file that is pulled from your server using Javascript/JQuery and AJAX. This is fairly easy, too. Perhaps the SESSION variable is the easiest as you just post to yourself and check which article was clicked and show it.

    So, let us know what you need next. We can help.

    Sponsor our Newsletter | Privacy Policy | Terms of Service