CUTCODEDOWN
Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: CMS and Theme methodology and directory structure  (Read 950 times)

xmohamadx

  • Junior Member
  • *
  • Posts: 23
  • Karma: +2/-0
CMS and Theme methodology and directory structure
« on: 17 Sep 2020, 10:38:46 pm »
Hello
I'm designing my first dynamic website with a simple cms for adding news, articles and products, not so complex. also, my intention is not to use any framework or pre-made cms(like poor man's), just html, css, js and php(this is why I'm here!).

What I'm looking for is simplicity, security and the right approach to design my directory structure and connections. I'm looking for good easy methodology.

My website pages (except home page and products), follows cutcodedown layout design, but some pages has no extras(like contact or about pages), and some pages has just one extra in left or right(news and articles pages) and some pages has both side(single article,news,product);

so I made this template to repeat for all pages:
page.php
Code: [Select]
<?php include("header.php");?>

<div class="heightWrapper" id="top">

<?php include("pageHeader.php");?>

<div class="hasLeftExtra mainSection widthWrapper"> // "hasLeftExtra/hasRightExtra" will be added by php if condition

<div id="contentWrapper"><div id="content">

<div class="subSection" id="">

// content will be included here, such as blog.php

<!-- # .subSection --></div>

// php if condition comes here if pagination needed
<div class="pagination">
.
.
.
<!-- .pagination --></div>
<!-- #content, #contentWrapper --></div></div>

// php if condition comes here if extra needed
<div id="extras">
// php if condition comes here for "leftSection"
<div class="leftSection">
// php foreach on each left section extra
<div id="" class="subSection">
// content
<!-- # .subSection --></div>
<!-- .leftSection --></div>

// php if condition comes here for "rightSection"
<div class="rightSection">
// php foreach on each right section extra
<div id="" class="subSection">
// content
<!-- # .subSection --></div>
<!-- .rightSection--></div>
<!-- #extra --></div>
<!-- .mainSection.widthWrapper --></div>
<!-- #top.heightWrapper  --></div>

<?php include("footer.html");?>


As it is a multi-language website(not the cms), the appropriate and easy approach seems to me is to store static commands and contents in separate sql tables. Each part in one table, for example: all menu items in one table for all language, or: all articles in one table for all languages, as for other static commands and contents(It has 3 languages). and the url can be same for all languages. let me know about cons of this approach!
The other way is to store all static commands in a php file inside arrays, and for content is to store them in different directory in a file as text.(It seems a nasty way to me!)
so the url could be:
Which one is better?

For cms, I go for few static pages without storing them in sql tables, it is not necessary for a simple cms. There is no complexity and many options in cms. For short cms should be able to add/edit/delete news, articles and products, also reporting about sold products.

Finally, this is the directory I made using Jason Knight outline on digitalpoint forums answer, the directory of cutcodedown and a tutorial in dcblog:

Directory:

/theme/themeName/ -- another approach would be removing theme and themeName, putting all theme files(not admin section) in root directory, but I didn't because of what Jason Knight said in digitalpoint forums answer:
Quote
First and foremost is to have a logical directory structure so I don't have to "up-tree" link and to maintain a separation between "content" and "theme" -- just as the HTML and CSS are separation of presentation from content. Having a plan for WHERE you are going to put things can work wonders.
/theme/themeName/template/fonts/
/theme/themeName/template/images/ -- presentational images
/theme/themeName/template/screen.css
/theme/themeName/scripts/
/theme/themeName/images/ -- content images
/theme/themeName/header.php
/theme/themeName/footer.php
/theme/themeName/pageHeader.php
/theme/themeName/home.php
/theme/themeName/products.php
/theme/themeName/page.php -- this is the layout for all other pages. bellow files will be included inside main subSection:
/theme/themeName/model/card.php
/theme/themeName/model/checkout.php
/theme/themeName/model/singleProduct.php
/theme/themeName/model/blog.php -- articles and news has same layout for displaying list of posts, blog.php will be used for both

for example, blog.php will be something like this:
Code: [Select]
<h2><?php echo $title ?></h2>
<ul>
<?php foreach ($posts as $post) { ?>
<li><!-- echo post title and summary --></li>
<?php ?>
</ul>

and for articles page, the page.php will be used as follows:

page.php
Code: [Select]
<?php include("header.php");?>

<div class="heightWrapper" id="top">

<?php include("pageHeader.php");?>

<div class="hasLeftExtra mainSection widthWrapper">

<div id="contentWrapper"><div id="content">

<div class="subSection" id="articles">

<?php
if ($pageModal == "blog") include("blog.php"); 
elseif ($pageModal == "singleProduct") include("singleProduct.php");
.
.
.
else echo $pageContent// for page that totally stored in DB and don't need a model, like contact, about, single article and etc.
?>



<!-- #articles .subSection --></div>
<!-- #content, #contentWrapper --></div></div>
...


sql tables scheme is something like this:
Pages                     News
=========             =========
id                              id
language                 language
modal                      modal(for example: blog, card or none)
url                            url
title                          title
content                   content
leftExtra                  leftExtra (for example: Articles, Products)
rightExtra               rightExtra (for example: News)
                                 date

/admin/login.php
/admin/index.php
/admin/template/
/admin/... -- other static pages to add/edit/list news, articles, products and etc.

/sources/config.php
/sources/functions.php -- functions such as: login, logout, DB connection , DB insert+update+delete(I can also create class for articles,news and products)

/index.php -- what index.php does is getting url and detect what page should be loaded and what functions should be called to get data from DB.

/setup.php



Apologies for length.
« Last Edit: 18 Sep 2020, 12:43:03 pm by xmohamadx »

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1049
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Re: CMS and Theme methodology and directory structure
« Reply #1 on: 24 Sep 2020, 02:50:26 pm »
Sorry for the delay in replying. Been a busy week.

Your "page.php' is wasting too much time having things that are (or should ) be static to all pages be in separate files, including markup in your logic.

For example, having header, pageHeader, and all the markup before the content be in separate files -- at least from the page's perspective -- is silly and wasteful. NONE of that markup belongs in your page... just combiine that all down to ONE file. Same for "extras" and the footer. MAke that one file as well.

That way all you need to do is:

Code: [Select]
<?php
include('header.php'):
?>

// Your content goes here
<?php
include('footer.php');
// closing the content wrapper and the entirety of "extras" goes in footer.php!

That way you get all the non-logic non-content stuff out of the unique page's code.

I tend to take it further in real code, wrapping all of my output in functions. That way it ends up:

Code: [Select]
<?php
include('templates/themeName/common.template.php');
template_header('Page Title');
?>

// content here
<?php template_footer();

IF for no other reason than to stop dropping in/out of PHP willy-nilly. But what do I know, I think PHP shorttags need to go the way of the dodo!

As to the language thing, I'd probably put the language AFTER the page name, and use "Friendly URI's" to make extracting what pages people are trying to view easier. At that point though you're looking at ditching the "one .php per user request" in favor of a "one index to rule them all" approach.
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

mmerlinn

  • Jr. Member
  • **
  • Posts: 77
  • Karma: +9/-0
  • Nutcake
Re: CMS and Theme methodology and directory structure
« Reply #2 on: 24 Sep 2020, 11:45:41 pm »
Basically, what Jason is saying is to include all of your boiler plate code from a separate static file rather than generating it every time.
The soul purr pus of a spell cheque cur is two valley date hour ignore ants.

 

SMF spam blocked by CleanTalk

Advertisement