Ok....so I created a new wordpress theme and I still can't get my custom code to work.
I want to be able to have a page which will output a list of items from the database, each item will have this URL format:
www.site.com/category/subcategory/?id=XX
The ?id=XX query should be at the end of the URL and will direct the user from the category page to the subcategory page showing specific data about the item with the XX id.
Each item in the list is wrapped in an tag in the category template page and the subcategory page uses $_GET. I've got one wordpress theme that works but on my other site, I use a different theme and it doesn't work. If a user clicks on an item in the list, the user gets directed to the subcategory page without the sql string attached. I'm not sure what to put in the functions.php file in wordpress (or whatever the file is called that handles functions) or in the htaccess. Any help is appreciated.
Update:
#Niels - I didn't make the code...I had two people make the code for me. Neither of them are professional coders but they got it to work so that's all I cared about. My website has never been hacked before but I need to find out how to get the code to work myself since the two guys who created the code are busy nowadays. Yea, I've been told about the sql injection.
I've got php code on the category page (http://www.mysite.com/category) that defines variables that will be used in the code, connects to the database, queries the database table, and then selects and outputs the items in the database table using the id of the item. The code uses a while loop to output the items so that the category page is basically a directory of items. Each item that gets outputted is outputted in this format: $itemname. Like I said, the code already defines these variables at the very beginning so the sql query already knows what to look for. When a user clicks on any item in the category page, the link should take them to the item's profile page, which is basically the subcategory page (ie: http://www.mysite.com/category/subcategory/). So let me be clear: when a user CLICKS on an ITEM in the CATEGORY PAGE, the user should be directed to the item's profile page, which is basically the SUBCATEGORY PAGE. This is where the /?id=$id part comes in. During the transition phase from category page to subcategory page, the query string should attach itself to the URL and the subcategory page will output data based on the data that is in the database for that specific item. For instance, if a user clicked on a link such as this: www.mysite.com/category/subcategory/?id=12, the user should be directed to the profile page of the item with the id of 12. The profile page, which is the subcategory page in our case, should output data for the item in the database that has the id of 12. That's how it should work. The subcategory page, or item profile page, will have a $_GET code so that it knows what data it is suppose to output.
Revised Answer
Look into WordPress' Rewrite API. It's definitely the more "correct" way of doing this.
Original Answer
Instead of using a URL query, try something like:
// URL: http://blahblahblah.com/category/pagetitle/15
preg_match_all('/[^\/]+/', $_SERVER['REQUEST_URI'], $matches);
$item_id = $matches[0][2];
echo 'Do whatever you want with Item ID ' . $item_id;
If a user clicks on an item in the list, the user gets directed to the
subcategory page without the sql string attached.
What do you mean exactly with "sql string"?
Could you describe, as concrete as possible, what links you have, examples and what page they should direct to and what those pages should do?
Also: I get the feeling you're a little out of your depth here and you're doing stuff with the database based on parameters from the URL . You should know that manipulating URL parameters to gain access to a database is a real easy way to hack a site. Please read a little bit about SQL Injection and how to prevent it.
Related
The situation is the next.
I have a template in which I fetch from an external api items [omeka-s], so result looks like a gallery.
The thing now would be adding individual display for each of the elements showing in the gallery.
How to make a redirect from one template to another and send the id of the element, so later on I could fetch from omeka api the individual data for that item.
Like each item would have tag with a link to the individual template and it should recognize which item was clicked for later fetching the item data.
How to mimic the wordpress functionality as if those items would be posts.
Looking for some ideas as how this could be made, million thanks.
Sorry I am not a hardcore coder. Need to solve Three problems and need your help please.
I need to be able to assign an user (i.e Editor) to a job from Edit Order Page (from a list of Editors dropdown menu)
I would like to see which orders are assigned to whom from Oder Table view next to status column (Admin view)
Each editor should only see their assigned order when they login to wordpress using their login credential
If anyone can provide the code or point me to a solution, I would really appreciate it.
Zed
I am trying to create an online store from scratch, with categories and product pages.
Since is my first WordPress store I'm stuck on this trivial problem which stopped me on my way.
The permalinks are set to Month and name just to know the settings.
I created several categories where I want to insert the future products.
The problem arise when I try to access a certain category link - www.mysite.com/category/books/ - it displays the error page.
If I access www.mysite.com/category/ it shows me the content of the category page created in the admin panel.
All I want to do is to display all books when the visitor clicks on www.mysite.com/category/books/ and so on.
It is simple. Go to wp-admin/options-permalink.php and make your own settings: /%category%/%postname%/
And add a prefix on the field below: category or whatever you want
Read here for more options
Actually I solved it in another way, by modifying the category.php page.
There I inserted this code :
$uri = $_SERVER['REQUEST_URI'];
$elms = explode('/', $uri) ;
$catName = $elms[4] ;
and it does the thing I need.
I wonder if there's a Drupal module that can do this kind of functionality: if i go to home page, it will take me to some subpath within the site. i.e. www.something.com will redirect to www.something.com/product/node/11.
I tried creating an alias and used Path redirect module but for some reason, i can't reach the expanded URL when going to home page. it will display the content of www.something.com/product/node/11 but still using www.something.com.
I'm thinking that this can only be implemented in Apache server, not inside Drupal?
Note that our purpose of doing this feature is whenever a new product is created, we want our home website to point to that (i.e. www.something.com -> www.something.com/product2/home, before www.something.com/product1/home). If this is configurable inside Drupal, the changes would be easier and can be done by a Drupal administrator.
You should be able to go to /admin/settings/site-information and set the Default Front Page at the bottom of the form. That doesn't do a redirect: the home page will BE whatever you set the default to.
Create a new view (Node type) named "frontpage_redirect"
As suggested in answer by Michael D, create and save a view configured to search for your specified criteria:
display: page display, path = frontpage-redirect
pager: 1 item
row style = Fields
fields: Node => Node ID
filters: node type = product
sort: post date desc
Save your new view
At admin/config/system/site-information, set your "Default front page" to the view display path above (frontpage-redirect in my example)
In the view edit screen select "Theme: Information" link in the Page display. Look for the most specific (rightmost) entry under "Field Node: Nid (ID: nid)" - should be something like views-view-field--frontpage-redirect--page-1--nid.tpl.php, but will depend on the view name and display name. Copy the default views template views-view.tpl.php into your theme folder using the filename from 3.
Edit the template and put this code in it:
if (isset($row->nid)) {
drupal_goto('node/' . $row->nid);
}
This way of setting up the redirect lets you drive it from Views, which gives flexibility. When your customer decides in six weeks that they want to feature only the latest red product on the frontpage, you'll be able to update the logic behind the redirect using the views UI. (And you can do it from your phone on the train home!)
You avoid the need to create a custom module (which is easy enough, but does add some complexity) or to move your site logic into .htaccess.
Using the Views module, create a new view that displays one full node, ordered by last created, filtered appropriately, then create a page display in the view. Then follow Graham's instruction to set the site homepage to the view URL.
Another way would be to write a very simple custom module that db-queries for the latest node created of the sort you want, grab the URL to the page, then redirect there using drupal_goto().
There are other ways to do what you want inside Drupal, but I can't think of any that are more direct and simple at the moment...
What you are asking seems wrong. Sorry if I misunderstand some detail, but it seems you should reconsider the problem on a higher level.
If I understand you right, you want to show the page for the latest product as the homepage?
If so, maybe you should turn that into show the latest project page on the homepage. That fits a lot better with the RESTfullness of the web. And with expectations of the users.
The pattern would then be:
GET /products/22 shows product 22
GET /products/23 shows product 23
GET /product/latest shows the last product (in this case, the page would be exactly similar to /products/23)
To achieve that, you can use views module.
On similar lines to Michael D's post, assuming you want to pull the most recently published product from a custom content type called "products," you could put something like this in your settings.php:
function yourtheme_preprocess_page(&$variables) {
$query = db_query("SELECT nid FROM {content_type_products} ORDER BY nid DESC LIMIT 1");
while ($row = db_fetch_object($query)) {
$redirect_nid = $row->nid;
}
if ($variables['is_front'] == 1) drupal_goto("/node/" . $redirect_nid);
}
modify the .htaccess file.
http://drupal.org/node/50322#comment-2456576
http://localhost/rkk/work-type/non-profit
I created a vocabulary and terms under for work-type. and I created some posts...
Then I created a View Block to list my entries, and assigned to a page... everything fine so far.
I display the work-type at entry details page. and I have a link "click to see other non-profit(assigned work type) works". When I click this link, it lists entries assigned to that particular work-type. thats fine, but it displays title/body/readmorelink :/ I need custom view for this page, like I did View Block for listing all posts...
Can I assign custom created View Block to this taxonomy entry list page? the url changes according to work-type, so how do I assign view to changing-url :/
Appreciate helps!! thanks a lot!
UPDATE FOR MORE INFO:
I have a vocabulary (work type), and terms under (corporate, non-profit, etc...)
I have a CCK for "work", and as a field I have select terms of work-type vocabulary.
I have a Custom Views Block to display works in a page (thumb, title, desc, link, etc.).
When I click a work, it goes to particular Work entry details page, I place a link in there "click to see other -term (corporate)- works", etc.
When I click this link, it displays the Work Entries under that particular term. it works fine. but it displays as default look (shown as below), but I need this page same as main works page list (thumb, title, desc, link, etc.) I already have a View for this, but how can assign this View to this dynamic url taxonomy page? I found the module http://drupal.org/project/tvi , but cant make it work.
It should be simpler to overwrite term pages with a view, there's already a pre-configured view for this : taxonomy_term (wich is disabled by default)