Jump to content

Custom Cms: Basic Questions


granGripau

Recommended Posts

Hi,I'm trying to build my own cms.Everything is going fine so far but I'm at the point where I want my content divided into articles. The main page would just show snippets of the articles and you can press "read more" to redirect the user to the full article. I have my database divided into navigation, pages, and users. I'm stumped as to what I should do with the php and with the database to get this effect. Any tips to get me going in the right direction? Also, part of the problem is that I don't know the right vocabulary to find apropriate tutorials i.e. looking up " 'read more' cms php tutorial" is useless, so any terminology tips would be helpful too!Thanks!

Link to comment
Share on other sites

Guest Alex Gower

well Your database should probably be set up with a table articles that contains the body text, title, date, posted by who_id , id, etcthen you should just have the user login, which in this case a user table will be needed, aka -> username, password, email, date_added, idthen on the index page you could use the php function word wrapwrap() and warp it to like 100... and then have a link saying readmore with a link like index.php?article=12 which would grab article number 12 from the database!if you need more in depth help then ask!! email me if you need too! np

Link to comment
Share on other sites

Great, I'll try that out. Thanks for your help!

well Your database should probably be set up with a table articles that contains the body text, title, date, posted by who_id , id, etcthen you should just have the user login, which in this case a user table will be needed, aka -> username, password, email, date_added, idthen on the index page you could use the php function word wrapwrap() and warp it to like 100... and then have a link saying readmore with a link like index.php?article=12 which would grab article number 12 from the database!if you need more in depth help then ask!! email me if you need too! np
Link to comment
Share on other sites

Hello again,I've created an articles table and the related php, I decided to add a snippets column in the table in order to have more control over the snippet content. With this code I can output the snippets in reverse order. What I don't understand is how to get the "read more" link to pull up the related "body_text".Do I need to put the url's and longtext in seperate tables?"articles" table:

CREATE TABLE `cms_sci`.`articles` (`id` INT( 20 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,`rel_id` INT( 20 ) NOT NULL ,`title` VARCHAR( 255 ) NOT NULL ,`snippet` LONGTEXT NOT NULL ,`body_text` LONGTEXT NOT NULL ,`who_id` VARCHAR( 50 ) NOT NULL ,`timestamp` INT( 20 ) NOT NULL,`url` varchar(20) NOT NULL ) ENGINE = MYISAM ;

and the related php:

			<?php				require("sources/connection.php");			$sql = "SELECT title, snippet FROM articles ORDER BY id DESC LIMIT 5" ;			$result = $conn->query($sql) or die(mysqli_error());			if($result){				while ($row = $result->fetch_object()){				echo "<h4>" . $row->title . "</h4>";				echo $row->snippet;				echo "</br>";				echo "<li><a href='{$row->url}'>< Read more ></a></li>";				}			}				?>  

Any help would be great!Thanks in advance.

Link to comment
Share on other sites

The read more link needs to include the ID in the URL, and link to a page that will look for the ID in the URL and print the associated article. e.g.:article.php?id=10That page can look up $_GET['id'] to figure out which ID to look up.

Link to comment
Share on other sites

Thanks for responding justsomeguy!I keep tinkering with the code based on several tutorials I found, now my links output "/articles.php?id=" but I can't figure out how to successfully pass the id into the link. I know i'm missing something really obvious... This is what I have so far (i also tried using $_GET but to no avail):(Please excuse my php ignoramousness.)

<?php				require("sources/connection.php");			//$page = (isset($_GET['articles'])) ? $_GET['articles'] : "1" ;			$sql = "SELECT title, snippet, body_text, id FROM articles ORDER BY id DESC LIMIT 5" ;			//$page = mysql_fetch_array($sql["id"]);			$result = $conn->query($sql) or die(mysqli_error());			if($result){				while ($row = $result->fetch_object()){				echo "<h4>" . $row->title . "</h4>";				echo $row->snippet;				echo "</br>";				echo "<a href='/articles.php?id='" . $row->id;				echo ">< Read more ></a></li>";				//echo "</br>";				//echo "<a href=\"articles.php?page=" . urlencode($page["id"]) . "><Read more></a>";}}?>

Link to comment
Share on other sites

echo "<a href='/articles.php?id='" . $row->id;You end the quote too soon, the single quotes are supposed to contain the URL. If you generate that page and view the HTML source you'll see something like this:<a href='/articles.php?id='10>The ID is not part of the quoted URL.

Link to comment
Share on other sites

Thanks justsomeguy! Now the link properly directs to the URL, but now I have a strange problem: all of the URLs just repeat the snippet content. For example I have the snippets loaded onto ".../articles.php" and the link redirects to "...//articles.php?id=1", the content of articles shows even tho i'm at the id=1 adress. I created a seperate "articlecontent" table with rows: id, rel_id, content, url. Even when I call up a seperate table the content repeats. I dont understand because I'm using the exact same method to pull up my about, services, contact etc. content. Any suggestions?articles.php:

<?php				require("sources/connection.php");			//$page = (isset($_GET['articles'])) ? $_GET['articles'] : "1" ;			$sql = "SELECT title, snippet, body_text, id FROM articles ORDER BY id DESC LIMIT 5" ;			$result = $conn->query($sql) or die(mysqli_error());			if($result){				while ($row = $result->fetch_object()){				echo "<h4>" . $row->title . "</h4>";				echo $row->snippet;				echo "</br>";				echo "<a href='/jquery/articles.php?id=" . "$row->id'";				echo ">< Read more ></a>";				}			}?>              <?php				$sql = "SELECT * FROM articlecontent";				$result = $conn->query($sql) or die(mysqli_error());				if($result){					while($row = $result->fetch_object()){						echo "<li><a href='{$row->url}' content='{$row->content}'>{$row->id}</a></li>";										}				}			?>

SQL:

articlecontent:CREATE TABLE IF NOT EXISTS `articlecontent` (  `id` int(20) NOT NULL AUTO_INCREMENT,  `rel_id` int(20) NOT NULL,  `content` longtext NOT NULL,  `url` varchar(50) NOT NULL,  PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;articles:CREATE TABLE IF NOT EXISTS `articles` (  `id` int(20) NOT NULL AUTO_INCREMENT,  `rel_id` int(20) NOT NULL,  `title` varchar(255) NOT NULL,  `snippet` longtext NOT NULL,  `body_text` longtext NOT NULL,  `who_id` varchar(50) NOT NULL,  `timestamp` int(20) NOT NULL,  PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

Thanks!

Link to comment
Share on other sites

Ok, I got it going by seperating the generated snippets page and the generated full text articles page:snippets.php:

<?php				require("sources/connection.php");			//$page = (isset($_GET['articles'])) ? $_GET['articles'] : "1" ;			$sql = "SELECT title, snippet, body_text, id FROM articles ORDER BY id DESC LIMIT 5" ;			$result = $conn->query($sql) or die(mysqli_error());			if($result){				while ($row = $result->fetch_object()){				echo "<h4>" . $row->title . "</h4>";				echo $row->snippet;				echo "</br>";				echo "<a href='/jquery/articles.php?id=" . "$row->id'";				echo ">< Read more ></a>";				}			}?> 

articles.php:

<?php				// open this				require("sources/connection.php");			$page = (isset($_GET['articles'])) ? $_GET['articles'] : "1" ;			$sql = "SELECT title, snippet, body_text, id FROM articles WHERE id='$page'" ;			$result = $conn->query($sql) or die(mysqli_error());			if($result){				$row = $result->fetch_object();				echo "<h4>" . $row->title . "</h4>";				echo $row->body_text;				}?> 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...