Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am building a new WP site and am pulling data from a secondary database and displaying it within WP pages. I am currently using the PHP Insert plugin and have successfully been able to display data on my site by typing in the PHP code right into the text part of the page.
I'm new to PHP and the backend of WP sites so I'm trying to figure out if I can reference other PHP files from within my code snippet or do I have to put all the PHP code in one place.
If I can reference other PHP files, then where do I put them from within my Wordpress environment?
Any guidance you can offer for me to learn this would be greatly appreciated OR if you have a recommendation for another way to organize my new PHP code to run on WP pages instead of a plugin. THANK YOU!
I have found that, except for the initial PHP code embedded in the WordPress page, it is easiest to maintain if all the other code resides elsewhere. WP sometimes does some funny things with loading pages due to showing parts of multiple posts on the home page, etc. so I have found it safest to use require_once() instead of require() or include(). I put the files in either a web accessible directory if they are designed to also run stand-alone, or in a non-web directory (generally preferred) if they should not be accessed except as part of your WP pages. Typically that would be required_once('/home/whatever/private/xyz.php') or require_once('/var/private/xyz.php') or something like that - the specifics will depend on whether you control the entire server or are working with what a shared hosting account gives you access to use. In some cases I distill it down to just a few parameters and the rest elsewhere - e.g.:
<?php
$id = 10;
$source = 'abc';
require_once('/home/whatever/private/xyz.php');
and let xyz.php do the rest as if it were running standalone with a couple of parameters passed in. The specifics will vary, but I've done it many times successfully.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
New to the world of php and dynamic websites I'm consfused as weather to use php from now on even to make basic webpages or continue making webpages with html and only use php when some data Insertion,Retrieval etc.. action to a database using SQL queries is required.. from a website
Don't know if I answered my own question
Clarification is highly appreciated
Thanks
I'm not sure what you think PHP does, but if there's no server-side functionality to put on a particular page then there wouldn't be any PHP code to write.
For example, if you have a page like this:
<html>
<head>
<title>My Page</title>
</head>
<body>
<p>This is my page!</p>
</body>
</html>
(Obviously an over-simplified example, but you get the idea...)
Well, if that's the page, then you don't need any PHP code. So why would you "use PHP" when there's no code to write for it?
When there's some server-side functionality that needs to happen, write code for it. When there isn't... well... don't write code for it.
If there are no dynamic elements within the webpage, then it is not necessary to write the page in a PHP file; an HTML file will suffice. That said, I would recommend saving the page as a PHP file anyways, because you may find yourself needing dynamic PHP functionality later, in which case you would need to convert the file then. By using PHP files in the first place, you will likely be saving yourself an extra step in the future.
PHP is not used just for contents saved in database, but also for contents that are static also such as header and footer section, imagine that your website is about 50 pages, and if you want to change one menu link! you have to edit all 50 web pages while using PHP is only needs to change one file that you included for main page.
In my website, I programmed those section with PHP:
Navigation menus
Header and Footer
Blog section
I use .php pages for all my webpages because eventually, I use a php code inside any of the pages to call from the simplest (header, footer) to buttons, insert texts, codes, anything that may need repetitive work but can be linked to its relevant .php document. And if any change is needed, one can simply change the one page and it will change everywhere. Dynamic works for me, even if I do not necessarily add a database to it.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm building a real estate website, and I want to have a page for every building in my database, so that I can find these in Google. I was wondering if I should create a static page for each of these, or if there's another way I can find them in Google.
EDIT:
I was rather wondering how I should structure these semi static/dynamic pages. I want to have a fixed title and description for the google results, but the photos and other info can be filled in via database info. Does this seem reasonable or am I overseeing things, or can this be done more efficiently?
Really, I'm just saying I want u fixed URL, title and meta description for google. I want the rest to be handled dynamically.
From your comments, I think you've misunderstood the relationship between files and URLs. When you, or Google, requests a URL, the web server can look at that URL and do whatever it likes with it. Whatever it returns is what shows in your browser, or in the Google search results.
The most obvious way for a web server to respond is to map the URL directly to a path on disk, and return the contents of that file, but that would mean no dynamic content ever appeared. The next obvious step is to run the program at that location, rather than serving its content, but that's still very limiting. Instead, the principle behind most modern websites is that the URL determines both a program to run, and parameters for that program.
So, in your case, the URL /property.php?id=42 might run the script property.php, which would look at the id parameter, and fetch the necessary content for property 42 - including the title, meta tags, pictures, etc - from wherever you have stored them in the database. With some extra server configuration, you can make /property/42-great-three-bed-apartment an alias for that same URL (note the 42 is still there, so we still have enough to look it up in the database).
This is basically how all modern websites work, including this one right here.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am planing to build a simple CMS (with PHP) for my own educational needs and I ran into a problem with design as I have never encountered this in any book or tutorial.
If I wanted to let used mess around the colors for example. How do I do that? The only idea I had was make a database with basically all such a options and then echo them to the site as normal CSS. But thet would mean it would load from DB every single time someone visits the webasite. It seems to me like it could overload the website. But again, I have never encountered such a problem. Or is there a way of doing this much more easily?
Thanks for every answer!
EDIT:
I would like to create a system that enables user to change css via CMS. For example background color, drop-down menu colors, text sizes, fonts and a lot of other stuff handeled by CSS. Simple customization.
So I was asking 2 questions.
How? What system should I use? No book/tutorial I read never covered editing CSS files using PHP so I have no idea how to do that. Or maybe there are better ways of doing it?
I had idea how I would store all customisable data. In database I wanted to know how big it can be and whether it would be a problem when posibly tens or maybe even houndreds of variables would be loading to the site.
EDIT2:
And btw I never worked with Wordpress or other CMS and I kind of expected that options like what I am looking for are present there, is that true? In my mind such a feature is essential for user inexperienced with computers. But from what I understand from link provided by Sam (http://css-tricks.com/css-variables-with-php/), it's not common. It's actually quite complicated thing and might harm performance of the website.
I hope I made my question clear now.
I know this has tons of downvotes, but you can cache your database queries. You can also mimic a CSS file using the header type in PHP. See http://css-tricks.com/css-variables-with-php/
This will allow the browser to cache the CSS file that was generated by PHP & MySQL. This means the database will only be called when the cache expires.
In terms of size you will never reach a limit with what you are describing.
Update
These sort of features are a bit unorthodox, using a cached version of the generated CSS file is basically mandatory.
What you can do is include a text editor within the CMS to edit the CSS file, each user can have their own CSS file that overrides the default one if changed. By letting them edit it directly they can change the layout themselves. You can even limit them to only changing colours / font-sizes etc.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Looking for ideas on how to go about working with a large set of .html files (50,000+) that are preexisting.
What I am trying to accomplish is to be able to keep the same hierarchy, links etc... but add content to them via php or whatever etc..
To be able to organize or route them into a php application or my own cms. I have been thinking ways to do this and come up with a few ideas but hoping to get some feedback from some pros.
I really only need to create something that will get the data once and add it to a cms that I develop. I have a script that I wrote to be able to index and search etc.. but how to go about using the contents and adding to them while keeping structure has me swinging a little. Any thoughts?
UPDATE: I found some tips that made this easier for me as well
Use a .htacess file and ad:
AddType application/x-httpd-php .html .htm
Then I can add includes into those files, I am note sure where to put this in the config file yet but will update when I know.
If you were to use a CMS like Wordpress, assuming your content follows some sort of regular structure, you could recreate the HTML frame as templates and then write a script that parses each HTML file and creates a post based on criteria like the HTML file name.
You can even match the file name by setting the slug on post creation, though you'll need a server rewrite rule to drop the .htm(l) if you intend to keep all the backlinks to the site.
I'm oversimplifying of course, as with 50,000+ files it isn't a trivial job to move all the data.
Perhaps automate it using something like this: http://wordpress.org/extend/plugins/import-html-pages/
The way I would go about it is to keep the html in a function which you require. Separate them logically as:
function output_html_one($link_here, $or_link_there...) {...}
function output_html_two($other_links...) {...}
When you want to output them with the files you have, just call the function, and it will be sent out. I am sure others will give you preferences. This allows you to give them access to variables through arguments, which is a downside, but it keep everything organized and provides some clarity as you can separate the raw html from the logic in your code. I am very curious to see what others say.
EDIT: I added $user inside of html_header so its clearer. For example, lets say you might want to check if a user is logged in. This gives you a way to tailor your html. Then you go to the files which contains this, you can jump in and out of the php tags in order to add dynamic content.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm working on a site which requires a very simple CMS - basically there's a block of text on the homepage that needs to be editable by the client. Their current hosting plan doesn't allow for a database, and including one will cost an extra $X a month which I think is unnecessary for such a basic system.
The site is currently built using Codeignitor. I'm planning to write the CMS part of it using either flat PHP or TXT files, are there alternative methods worth considering, and what are the pros/cons?
Okay, so further to this, I've opted for a custom flatfile system. I looked at a few of the recommended non DB CMS systems and they seem quite good - particularly this one which I later found: http://get-simple.info/
The reason for building my own is mainly due to the fact that the site is already on the Codeignitor Framework, and I don't want to rebuild it using a different one.
So my question now is - if my system is storing data in two txt files: one for userdata and one for site content, are there massive security issues if I set the sitecontent file permissions to RW? The site is quite small and I can't imagine anyone would want to hack it, but I'd still like to know if there are any major security implications.
Try http://www.opensourcecms.com/
example of some that might interest you
PivotX
pluck
razorCMS
cushyCMS
its ftp's into your hosting account, reads your html, and looks for tags that have a class="cushy" and makes those content feilds editable. its good forwhat your wanting.
I once solved this problem by simply putting markers in an HTML file, as HTML comments, and then had my PHP script parse the file and insert the desired text in between the markers. Done this way, you need no other files other than the PHP that handles the form submission from the CMS and a static HTML page.
In words, read the file into a string, explode() the string using the marker as the delimiter, modify the second (if you have a single editable section enclosed by the markers) array element to contain the new text submitted by the user, then implode the array back into the string, then write the string back as the complete file.
What about sqlite? it is just a file, no need to install anything? But if this is also not welcome, you could just keep the contents in txt files and have a php to read it, put to your template.