Wordpress: How do I convert a generated URL (permalink) to a pretty URL? - url-rewriting

In a plugin, I am generating a paginated link to a category,
i.e. http://localhost/?cat=17&paged=5. The category is known by slug and id.
Is there a way to have this URL converted to the user defined "nice permalink" format,
i.e. http://localhost/category/foo/page/5?
(Assuming we're running Wordpress 2.8/2.9+)
Edit: Since there are some misunderstandings about what I'm trying to achieve, here's what I have:
The category ID
The page number (i.e. the fifth page of that category's archive)
With these data I can create the URL to that page, which would be, for example, http://localhost/?cat=17&paged=5, and that works well. The problem is of a visual nature: If the user has pretty permalinks enabled, then this won't fit in very well.
Question is: How do I get the correct, pretty permalink (i.e. http://localhost/category/foo/page/5) from (or for) the information I have?
Edit 2: Obviously if a user has pretty permalinks disabled, then there are no pretty permalinks. I know that, and that is really not subject of the question ... For the moment, let's just assume the user has an arbitrary permalink setting. I generate a link, and it should look like the user wants it to.

Have you looked at the WP_Rewrite?

Does All In One SEO meet your requirements? I actually bought the "pro" version for like $30 USD and it was well worth it.

My Wordpress installation (2.9.2) does this automatically - canonical URLs have been built into Wordpress for some time. Maybe your plugin is disabling this feature?

I'm guessing you already figured it out but I just wanted to put this out for others. I think I understand your situation. If I've read your question correctly, changing admin permalink settings does not apply.
You can get the category ID then use get_category_link() function to get the 'pretty' permalink. Then append the pagination to the end.
You could explode the permalink to get the category ID and pagination number, then use the step above to put it together.
Is this what you were looking for?

The correct way to generate the link would be to use get_category_link and add_query_arg
In your example, the following would work:
$category_link = add_query_arg( array('paged' => 5), get_category_link($category->term_id));
This will generate the URL and Wordpress will redirect to the correct page.

check this page out, it explains pretty permalinks pretty good.
http://codex.wordpress.org/Using_Permalinks
You should find these settings in
Wordpress->Settings->Permalinks
I think
/%category%/%postname%
in the direction what you want
You can also try to redirect your url using htaccess, here are some examples:
[http://]perishablepress.com/press/2008/02/06/permalink-evolution-customize-and-optimize-your-dated-wordpress-permalinks/
Sorry darf bis jetzt nur ein link posten pfft... :-(
kind regards,
Mahatmanich

Related

Kademi - how to set canonicals on a product page

I am trying to set a canonical on a product detail page to prevent duplicate pages of the same URL.
Our client's website has 1375 however search engines are picking up 2890 because the overwhelming majority of pages are being rendered as duplicate such as the below several examples.
Same product example 1:
https://www.waterware.co.nz/store/1-function-hand-shower
https://www.waterware.co.nz/store/FW556
Same product example 2:
https://www.waterware.co.nz/store/1-function-hand-shower-black
https://www.waterware.co.nz/store/FW550BL
Same product example 3:
https://www.waterware.co.nz/store/1-2m-shower-hose-metal-wound
https://www.waterware.co.nz/store/FH112SS
And repeat 1375x.
I have since discovered where the 2nd version of the URL is coming from - its the favourites icon on product detail page - and will begin removing / adjusting these.
However in order to maintain best SEO practices I need to find a way to set a canonical.
I am aware that this could be done MasterTemplate.html. However there does not seem to be a way to discover the correct scope when in the master template file.
Any suggestions?
Thanks
SEO integration was commented out in KCommerce2, but it will be re-enabled in the next release later this week
This uses the webname property in the canonical href.
It also inserts the meta description field using the brief if its available, otherwise the product body.
And it also generates a meta keywords tag, using the product code, categories and brand.
To use this once available, you will just need to update to KCommerce 3.1.3 or later.

How do I get Magento to always give the /catalog/product/view/id/ style url for products?

I want Magento to always generate product urls in the format:
www.example.com/catalog/product/view/id/123/s/product-name.html
instead of the rewritten
www.example.com/product-name.html
The reason for this is mainly so that I don't have to worry if something happens to all my rewrites, or so I can feel free to truncate and rebuild core_url_rewrite if something goes wrong and it gets too big.
I don't want to stop using rewritten urls entirely. I like them for categories. I have fewer categories, and I very rarely change the names. I hate feeling like I can't change the name of a product because it will make the core_url_rewrite table grow and mess up any backlinks I've generated if I lose my rewrites. Also, I still want my current urls to work for as long as possible along with the /product/view/id urls.
Is there an easy way to do this without rewriting methods that I'm missing?
Or do I have to override some getProductUrl method? It looks like the answer lies in the getProductUrl() method in Mage_Catalog_Model_Product? That class seems to use the getProductUrl() method in Mage_Catalog_Model_Product_Url.
But again, if there's some simple configuration setting that would do the trick, I'd rather do that.
Magento handled it by own. Please follow the below steps.
1.Login to the admin panel
2. Then System >> Configuration >> Catalog >> Catalog >> Search Engine Optimization
3. Then Change the settings as per your requirement
4. As per your current requirement "Use Categories Path for Product URLs" will be YES
5. Then try to reindex full Via SSH.
Hope it will works.
Thanks

How can I get a list of all CSGO items including skin name, quality and rarity?

I'm not looking for details of a specific player inventory, but a list of all items for CSGO. What I want is details of the weapons in particular, but including skin name information and rarity.
To make it easier to explain this site has the information I need, except rarity.
http://csgo.steamanalyst.com/list.php
By using the following api url I can get weapon model names but not skin names (ie. "Zirka")
http://api.steampowered.com/IEconItems_730/GetSchema/v0002/?key={YOUR_API_KEY}
I haven't found anything regarding skins in Steam Web Api.
Lists of all skins as well as rarity and corresponding weapons are in "paint_kits", "paint_kits_rarity" and "item_sets" sections of /csgo/scripts/items/items_game.txt file.
As for their correct names, those are in /csgo/resource/csgo_YOUR_LANGUAGE.txt. Looking like that
"PaintKit_so_red_Tag" "Candy Apple"
Won't be hard to make php or python script to get all of it and put it in a database for ease of use.
For skins images you could get weapon and skin name from the above, and do a foreach curl loop to get content from div with "market_listing_largeimage" class using for example simple_html_dom.php, from url http://steamcommunity.com/market/listings/730/{ITEM_NAME}%20%7C%20{SKIN_NAME}%20%28{USAGE_THINGY Ex. Well-Worn}%29
Just remember to replace all spaces going to the url with %20 but that depends on what you use to get the page. You could do a foreach on the usage thingy since some weapons don't have some variants on the market, curl could return wrong page. Nothing that a simple if+foreach couldn't fix.
Also do it only after skins update if overused you could get blocked from valve website for spamming. You could also use SteamWebApi and game news to check for new versions and update it automatically then. Just use your imagination and google.

Different URL keys for different language CMS pages

I'm currently setting up a Magento shop that will support a few different languages.
One issue that I ran into is that I can't find out how to link two CMS pages together, so that when a user switches their language, they are automatically forwarded to the current CMS page but in their preferred language. One option would be to use the same URL key for both pages, but that wouldn't be very user friendly as some users would then see URL keys not in their native language.
Let me give you an example:
I have an "About us" page. In the English version of the store, the URL of that page is /about-us. Now a German user lands on that page and switches his language. But because the German equivalent to "About us" is "Über uns", the German version of that page is at /ueber-uns, so the user would be presented a 404 page because no German version of /about-us exists.
Does anybody know how to solve this issue?
Update: Did some more research and found nothing. I can't believe I am the only one with this problem? The go-to solution, using the same URL key for all languages, seems very ugly and not very user friendly!
So, the only solution that I found was to manually create a redirect for each page in the Magento Rewrite Rules. Do do that, go to Catalog -> URL Rewrite Management and add each page in the following format:
So if a user is using the Francais store view and requests /url-in-english, the redirect will kick in and redirect the user to /url-in-french.
This is of course not an ideal solution, it would be preferred if two pages could be "linked" directly, but I suppose I will have to use this for the moment. If anybody comes up with a better solution feel free to add yours!
I have seen this bug in Magento CE 1.8.0.0. The problem here was a wrong assignment in \app\code\core\Mage\Core\Model\Url\Rewrite\Request.php.
To solve this problem it is sufficient to change the assignment of $fromStore in the protected function _rewriteDb() within the Mage_Core_Model_Url_Rewrite_Request class from
$fromStore = $this->_request->getQuery('___from_store');
to
$fromStore = Mage::getModel('core/store')->load($this->_request->getQuery('___from_store'), 'code')->getId();
with the result that we can access the $stores array with the right key (with the store id instead of the store code). With this the if statement
if (!empty($stores[$fromStore])) {
works in the right way.
As a reminder: Do not modify core files. Just copy \app\code\core\Mage\Core\Model\Url\Rewrite\Request.php to \app\code\local\Mage\Core\Model\Url\Rewrite\Request.php before any change.
You will find this answer in German here: Rewrite von Seiten in verschiedenen Sprachen und verschiedenen URL Keys in Magento
Above solution works but takes a while. We just did the following to rewrite the language changer url when on a cms page to go to the base url:
Add the following code to app/design/frontend/default/template_name/template/page/switch/languages.html after the part where the $url variable is filled (on our it was like
$url = /*explode( '?',*/$_lang->getCurrentUrl()/*);*/;
so we added the following:
if(($this->getRequest()->getModuleName() == 'cms') && strpos($url,'.com/')){$url = strstr($url, '.com/', true) . '.com/';}
elseif(($this->getRequest()->getModuleName() == 'cms') && strpos($url,'.de/')){$url = strstr($url, '.de/', true) . '.de/';}
elseif(($this->getRequest()->getModuleName() == 'cms') && strpos($url,'.nl/')){$url = strstr($url, '.nl/', true) . '.nl/';}
What I did here is check if on a cms page and check if the url contains either .com/ ; .de/ or .nl and strip the part before then add the domain extension back.
in our example: http://www.mega-watch.com/about-us?blabla will become http://www.mega-watch.com/
Hope this helps someone out..

Displaying specific content to specific user in Joomla 1.5

To be short, It's a website for an investigations lab.
I need to display specific content (lab report) to specific user. Users will be given a username and a password when leaving and will be asked to login on the website to access his/her report with the credentials given to him.
So , it's a "specific content" for "specific user" - Moving to 1.6 is not an option.
I have a solution in mind but involve a lot of core hacking and will take some time ... If any one been in a similar situation or have an idea in mind I would appreciate your help.
Ok, this can be done but it's going to take a little trickery to get there. First, you are going to need a way to post the lab reports and associate them with a user. I would use K2 for this since you can add the report as an attachment to an item. You can also add extra fields to K2, which would be the next step. You'll need an extra field where you can enter a user ID number that you will use to determine if a user is allowed to view the content.
There are several steps you will need to take to now filter the content so only the associated user can see it.
You will need to get the user ID once the user is logged in:
$user =& JFactory::getUser();
$usr_id = $user->get('id');
You'll need a menu item that links to a K2 Category where all the lab reports go.
You'll need a subtemplate with a modified category_item.php for that category that only displays the associate reports:
if($this->item->extra_fields[USER_ID_EXTRA_FIELD_NAME]==$usr_id){
all the category item stuff
}
You'll need a subtemplate with a modified item.php for the category that again blocks users other than the associated user, basically the same code as #3 to either display the content or an error message.
The only other way I can think of that you can accomplish this would be to use an ACL component with a group for each user.
The K2 method with subtemplates would not require any core hacks and will work with a little work.
You can achieve what you want with Flexicontent http://www.flexicontent.org/ and Flexiaccess
Flexicontent is a K2 type component and I use them interchangeably. With Flexiaccess you can create items that are only available to certain users.
No hacks required.
Bad News: That cant be done with standard Joomla 1.5 (without hacking)
Good News: You can use one of the free or commercial Extensions for Joomla to accomplish that. I would suggest for example:
Admin-User-Access
http://extensions.joomla.org/extensions/access-a-security/backend-a-full-access-control/9040
Or you can search for yourself:
http://extensions.joomla.org/extensions/access-a-security/backend-a-full-access-control

Resources