Integrating WordPress with a website, generically - php

So, I've read The Loop and I got the hang of it. (I created a page that lists the 3 most recent posts, a page that shows a page (as opposed to a post), and so on.)
However, it seems silly that, in order to integrate a WordPress blog into an existing site, I'd have to replicate all the different kinds of pages (lists of posts, the posts themselves, pages, etc.)
Is there a generic way of doing this?
The full idea is something like this.
The blog itself (with its ugly default template) is installed at http://blog.example.com.
I want to integrate the blog into an existing site, at the URL http://example.com/blog.
I'm doing a mod_rewrite that forwards the entire query string, e.g. http://blog.example.com/?p=7 gets rewritten to http://example.com/blog?p=7.
Now, in my PHP code at http://example.com/blog, I want to do something like this:
query_posts($_GET);
// display results
wp_reset_query();
That's where I'm stuck. Basically, I want to display exactly what's in the "content" area of a default WordPress template, on my site, according to whatever the query string dictates. Almost as if I were just using an iframe. I would rather not have to parse the query string to figure out whether I have to loop through this or that or turn off the $more global or not, etc.
What am I missing?
Instead, should I be installing the blog at http://example.com/blog and creating a template that mimics the website? This seemed complicated so I didn't go this route, but maybe someone should change my mind.
Appreciate any help, including advice for alternative designs.

Have you considered outputting the blog into a full rss/ outputting the blog as json and then pulling it in that way?

Related

create a content-only page for mobile news feed in modx

I've been tasked with providing the backend for a news feed that will be used by our company apps. The feed will pull articles from our current website, which is built with ModX (evolution). So far, I've designed the feed to send JSON through a specified url containing the needed information. It's currently in the following format (using Ditto placeholders):
{
"title":"[+longtitle+]",
"description":"[+description+]",
"link":"[(site_url)][~[+id+]~]"
},
Here's my issue - the link I'm providing through the JSON (in the link tag) opens the full, desktop version of the page. Our current site is not responsive, and was not originally designed to handle mobile devices. We would like to open a small, clean page showing ONLY the ['content'] of that particular article. I'm looking for a way to link to a page showing only this content - no header, no footer, nothing.
I know that I could create a new page to handle all of this, but it needs to be dynamic. New articles are created regularly, and I'd like to avoid having to add another page to handle this for every article, while also making it simple for the writing team to integrate this feature.
One of my ideas so far is:
Pass a GET parameter to the URL "link" in the JSON - something like - www.mysite.com/article1?contentOnly=true. Then, in my article, detect this parameter in PHP and handle accordingly. I would need this snippet on each article written, so it may cause issues down the road if our staff writers forget to add it.
I haven't worked with ModX long, so I'm assuming there's a better way to handle this. Any ideas would be greatly appreciated. Please let me know if I need to provide more information.
I am not 100 % sure how you have done this, but here's my tip.
Don't use the resource itself to output the JSON. Doing this based on a GET-paramter will required the entire site to be uncached. Instead, use a single resource for the feed and supply the id/permalink there.
For example: mysite.com/feed?id=1, mysite.com/feed?latest or something like that.
Done this way, you could have an empty template with just the snippet that is parsing to JSON in it. This has to be uncached of course, but the rest of the site could be cached as normal.

Prestashop - custom template link

I'm starting with "PrestaShop" and I just can't figure out, how to put a link in template to custom page I created in CMS module... I thought, there might be some easy way, as there is in WordPress, like "get_permalink(ID)", but there's nothing like this and I can't find anything about this anywhere and it just drives me mad.
So, here's the deal, I've got a custom template, and there are some top links, like "About Us". I've created this page in CMS and it has ID "6".
How do I make this bloody "PrestaShop" to generate a link to this page in my template file?
About
I think you're looking for SMARTY template tags and custom variables defined for Prestashop specifically. The one the you probably need is {$base_dir} which will be translated to http://www.yoursite.com/ obviously with appropriate protocol (non-secure HTTP or secured HTTPS).
After that, you only need to include page URL, which you can get from Admin->Tools->CMS section.
If I find any specific tags that you can use to call the content, I will update my post here.
Your Text
the "WHAT goes here" is just the url you want your link drives the client to when clicking on that link.
You need to understand a little minimum of HTML for this I guess. Check html tag a meaning .
Prestashop has a fairly good and extensive documentation. Two and half seconds googling drives me here, just like answering your question it looks like.

Open page in Joomla

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?

Why Can't I Include A Blog?

I commonly run into a scenario where "the powers that be" want an exact copy of a page in multiple places on a website. Rather than actually duplicate the content, all I do is override the section in the nav that is highlighted, and then include the page. The final page looks something like this:
<?php
$top_nav_item_id = 'teen';
include('../interests/teacher-resources.php');
?>
This typically works. I am trying to duplicate this for a blog category, done in wordpress. All I seem to get is a blank page, no matter what I do. I've tried all of the following lines:
<?php
include('../blog/index.php');
include('../blog/type/teen/index.php');
include('../blog/type/teen/');
include('../blog/');
?>
Does anyone have any ideas? Is this a URL rewriting thing? Do I have to include the template file for that particular category?
Any help is appreciated.
PHP include expects files, not URLs, so it doesn't have access to the URL namespace exposed by WordPress. Those files don't exist on-disk; mod_rewrite first turns the pretty URLs into an internal request to index.php, WordPress figures out what you really wanted based on the original URL, fetches a bunch of stuff from the database, then produces the page.
This is a pretty complicated topic, and one that isn't very apparent from the start. This page should help you get started. The key is to include the WordPress blog header - explained on the linked page. You'll probably also want to check out the WordPress Codex for resources on using the WordPress engine's API.
ini_set('display_errors', true);
error_reporting(E_ALL);
No idea what's going wrong, but it does. Maybe Wordpress can't find it's environment, maybe some variables are being overrided... Actually it's a bad idea to include solutions like wordpress, because you never know, what global variables, functions, classes will intersect.
PS: And, by the way, include uses file system paths but not URLs.
For similar issues I use iframes to include the copy of the content. You can write the original page to look for an "?embed=1" flag in the url, and only include the embeddable content in the main page when the embed flag is present (so you can leave out toolbars and frames that would be redundant.) So the iframe src url would use the ?embed=1 tag to embed the content.
This solution is a bit of a hack, but then, the problem is a bit of a hack to begin with.
I received a good explanation of why I couldn't include the blog page, but not any alternatives that would work for me.
My final solution was to modify the category template for that page directly. As stated originally, I use $top_nav_item_id to control which menu item is highlighted in the nav, to give the appearance of the page belonging to that section. Rather than override this, I simply made it conditional on a query string. As long as the user is following legit links on my site, they will get the correct query string and have no problems.
$_POST is disabled in Wordpress. $query_string (built into WP) uses some sort of caching, and would always display as it was first loaded.
Final solution:
if(strtolower($_SERVER['QUERY_STRING'])=='display=teen') {
$top_nav_item_id = 'teen';
} else {
$top_nav_item_id = 'programs';
}
Thanks to all who tried to help.

How do I make the Preview link on a WordPress post or page point somewhere else?

I've done a lot of small projects on the side lately where the client wants a good chunk of the website to stay the same, they just want to be able to edit particular "areas" of the site. Namely, some text in some box somewhere.
I've found that WordPress works for this pretty well. The interface is nice and friendly to use, and it's got lots of work behind it so I don't have to reinvent wheels, fix bugs, etc.
So what I wind up doing is making PHP pages which look like what the client wants, then making the content editable areas contain a particular post or page, which is what is editable in WordPress.
I'm having the particular page's contents displayed on the page using code like this
<?php echo apply_filters('the_content', $page_Contact->post_content); ?>
where $page_Contact is a variable defined elsewhere.
However, the "Preview" or "View Page"/"View Post" function on each page/post goes to the logical WordPress location and this is not the effect I want in this case.
So for example I have pages like this
www.site.com/index.php
www.site.com/about.php
www.site.com/contact.php
And so forth.
WordPress wants to have the "View Page" and "Preview Changes" links go places like
www.site.com/?page_id=2
www.site.com/?page_id=8&preview=true&preview_id=8&preview_nonce=45522671f5
Which is a problem because, in the permalink structure above, both of those go to the index.php page which, except for the page I'm using to structure index.php, it's not where I want the user/editor to go. And none of the cases above allow any sort of preview (which is a concession I'm willing to make given how I'm doing this)
Is there a way, preferably using a plugin to rig WordPress such that the preview for a page in the dashboard goes to a preview of the non-index.php page where the content will be housed? So for example the link for the "Contact" page in WordPress's dashboard goes to contact.php instead of ?page_id=2? This is a deal where I'm trying to get this done in the editing interface and I'm not concerned about the links in the site itself.
Obviously I would need to maintain this per-page and this would be a situation where new pages don't go up unless I put them there.
Take a look at the preview_post_link hook in WordPress -- it should be called when generating that link, and you can use that in conjunction with a custom field (or some logic) in order to construct whatever preview link you like.
Have you considered page links to plugin for wordpress? Also changing permalinks?

Categories