I know the title is messed up, but basically I have: news.php which is kind of a dashboard where I get all news from DB and I can perform actions on them (update, delete, insert new) and also I display them in a traditional way (tables). The problem is I want the title of the first news to be displayed on my homepage(footer), but when I include the news.php file withinclude(), the hole code it's included and on the home page I get all the things I have in news.php, all the news, the buttons (edit, add, delete) and everything else. Is there any way of including one .php file but not displaying it ? I want to create a function that only displays the title of the first news but I can't because the hole code is imported and displayed.
Thank you for your quick answers. Having only this small problem, I'll just create another file where I get the latest news without using frameworks
You need to create a function library so that you can call specific segments if you want.
But here's a quick shortcut. copy news.php into news2.php. go into news2.php delete all the parts you don't want; include news2.php instead
You could try making another single file called firstnews.php which would only retrieve that particular first news item and include that.
You should maybe read up on MVC frameworks, its a good way to seperate data retrieval, manipulation, and then actually showing the data. For example one php file would hold a function that retrieves all news item, and another function that only gets the latest news article. Then the actual file which shows the user data would simply choose which function it wants to use.
Its a lot to get into, but the codeigniter framework is a great way to get familiar with MVC frameworks and it will open a lot of doors for you.
CodeIgniter Homepage
Manual on how to setup and use CodeIgniter
For now though try just making a seperate php file that only retrieves the latest news item instead of all of them and include that.
Hope this helps!
-Gui
Related
Page creating in PHP: I'm trying to learn how to make a cms but I couldn't understand something. For example in Wordpress when you click "create a new page" button what is happening at the backside? For example now I don't have any page.
I want to create these pages dynamically:
Home
About
Contact
After I want to add this pages in my menu. What is the best way to do that?
Questions:
Should I create a new php file to do this or just get data from my database which belongs to each page?
How I add these pages in my menu dynamically ?
What is htaccess? I couldn't understand that exactly it does relating the the processes of the files.
There are tutorials on internet but they always show how to get articles from database. When I have another item (for example a slider) I need a real page.
Can somebody suggest me a simple tutorial, or provide a clear explanation which explains the logic simply.
I have created something similar. This is how I did it (may not be the best way but it is certainly the easiest).
Create a template file and insert tags (!Title!, [[Title]], etc) where you want the new pages data to be inserted.
When creating a new page, read the contents of the template and replace the tags with the data submitted (I used titles, desc, h1, etc but this can also be achieved through a simple content function)
The user selects/creates the directory using mkdir()
All this is then stored in DB ready for the user to navigate to.
You can then use the DB entries to build a navigation menu
At the top of every php page on my website is a large profile card that calls data from a relational database in mySQL. This is the only thing I'm using the database for.
When I create new pages, I have to go through the code and update the id# for all of the php queries in the profile card. It's not hard. I just do a 'find and replace all' and I'm done.
However, I am wondering if there is a way to just put the id# at the top of the page once and have all of the php queries reference that id number. If this is possible, I'll be able to move that bulky profile code to my header.php page which already contains the template and menu stuff.
The only software I use is notepad++ and xampp.
Create a constant in a config.php:
define('MY_ID', 12);
In each of your file:
include('config.php');
So you need to change the value of it only once.
A much better way, if you write a function, what gives you back this whole profile section, so you can change the layout of this also, in 1 place.
I have already working guestbook script, which I’d like to add to my prestashop on a separate page. The problem is, that I can’t find where to place it.
I’ve browsed through a lot of modules, but it looks like all of them are registering to either left or right column hook. What I need is to display the script in the middle column, which basically consists of only calling one or two methods that will render out the correct html.
I don’t need to do anything with configuration or accessing the prestashop database, or even create a page in the administration. Basically the same thing I’m trying to achieve could be done using an iframe in a CMS page, where the iframe’s url would link to the guestbook script, but that really doesn’t seem like a clean solution to me.
Is there any simple way to make a separate php script display on the “main” center column?
Isn't the include able to help you?
<div><?PHP include(something)?></div>
<div><?PHP include(something else)?></div>
etc
you can place if conditions if needed.
I'm using Jumi to echo php code and then showing that in a Joomla Article, and everythings working fine. Now I want to do this:
The output is basically a list from a database like this:
Name Price Type
A 1 T1
B 2 T2
In this list I want to include links to only show items of the same type, so "T1" would like to a page only showing things of type T1. So I thought I would do this by making a new page that takes a type and then get all the items of that type from the database. Without Joomla this wouldv'e been a piece of cake, with Joomla I'm not quite sure where to begin.
How should the a href=... tags in the html code printed by my php script look?
Is my basic structure still correct, and if so, how do I make Joomla open the new page in the normal frame and not replace the whole Joomla page. some kind of target-frame attribute?
EDIT:
I know I should be using a component instead, however I just need to get this working before going on vacation in three days. I will do it properly when I get back.
I don't mind if the entire page reloads, what I do need is the Joomla menu, header-banner and other things around the page to be loaded as well. If I just use a href=mypage.php I assume the header and everything around it will disappear.
I think you are going about this all wrong. You shouldn't be using Jumi to run php in your articles. You should design a component. Although this will take a tiny bit longer to setup initially it will save you time in the long run and prove to be much more flexible than using Jumi in a single article. Have a look here on how to create a Joomla component - http://www.joomladevuser.com/tutorials/components.
a href= tags should not be any different from any other html you have ever used.
E.g. echo 'link';
To make just the frame/div/table/etc reload rather than the entire page you will need to implement some AJAX. I have answered a question on how to do this with Joomla components before, see here: how to use Jquery AJAX in Joomla Components?
Since I had some comments on the formulation of my question, I decided to rewrite it completely. And also, I understand a little bit more about wordpress so it should make more sense now.
So, let's start with what I'm trying to accomplish by using a simple example:
Goal:
Make a search engine for some products and link to them using a database to generate the information.
Result:
http://my.site.url/wordpress/<plugin-name> <-- The page with the "search" and "search result
http://my.site.url/wordpress/<plugin-name>/products/<product_name> <-- When click on a search result
Part 1:
I want to make a plugin with the name "plugin-name" Right now, I put my code in
http://my.site.url/wordpress/wp-content/plugins/<plugin-name>
On the activate, I create some tables with some data. Since there is no page yet, I create 1 on the fly using the API call 'wp_insert_post'. I give the name and slug "myPlugin".
So, when I go on the main site, I can see my newly created page "myPlugin". But right now, there is no content attached to it. To do so, from what I understand, I need to create a page in my plug-in directory named "myPlugin.php".
http://my.site.url/wordpress/wp-content/plugins/<plugin-name>/myPlugin.php
So, how do I link the page I created manually and the source file in the plugin directory?
Part 2
When clicking on a link in the search result, I would like to have a page "product.php" and display its information. So, is it possible to create a "temporary url" for the result using sub pages (see result at the beginning)? And if possible, how can we achieve that?
Thanks in advance and I hope it's clearer.
u can find how to create plugin from
http://ditio.net/2007/08/09/how-to-create-wordpress-plugin-from-a-scratch/
in plugin write function for search(as per u r logic) fetch result
create a custom page refer video from www.wordpressmax.com/customize-wordpress/custom-page
in custom pages template in between get_header(); and get_footer(); call search function and display records.
Thats it.
thisMayhem is right. This sounds like a bunch of nonsense. But, if you're trying to make a WP page that executes some custom PHP, look up the WP template hierarchy.
What you can do is this:
create a WP "page" - call it "Search results."
create a template directory file called page-search-results.php (filename corresponds with slug of page from step 1)
put some generic header/footer stuff there (see other template files - most often it's just a question of putting in <?php get_header(); ?> and <?php get_footer(); ?>)
put PHP code in that thar page. in them hills.
if you use a caching plugin, may want to put an exemption for /search-results/
So, when someone pulls up http://your.site/search-results/ - your custom PHP code will execute. It's up to you to make that logic and communication happen - whether via $_GET or $_POST, etc.
I'm sorry you're experiencing some problems. Unfortunately as we say above because it's a 'one off' for a client project we can't support it - it works for them :) Feel free to rip it apart and retest and if you have any success let us know.