I am trying to make a news section for my homepage "index.php". So I use ajax to load "pages/news.php"'s content into a news div in index.php. This pages/news.php is supposed to pull out latest posts and format them nicely. The blog is in localhost:81/blog/
When I view localhost:81/pages/news.php, it can display the posts, no errors. But when I run localhost:81/index.php, it said
jquery-2.1.4.min.js:4 GET http://localhost:81/pages/news.php 404 (Not
Found)
If I remove this line in pages/news.php:
include(dirname(__DIR__) . '/blog/wp-blog-header.php')
index.php won't have error, but of course cannot view the posts.
If I copy the code in pages/news.php to index.php, it works (of course with appropriate including path). I am very confused here, how come using the same code but retrieving news.php content from ajax does not work but news.php itself works?
Could someone please advise me what has gone wrong?
Thank you for your time reading.
It turned out that this is a common issue: wordpress forces user to use ajax in a specific way. The instruction is here: http://rocketpopmedia.com/discover/2013/06/21/wordpress-ajax-and-the-404-error-youre-receiving/
Related
I've been looking for the answer I seek in many posts before. But none of them worked for me.
I'm learning CI currently and want to implement it with admin panel template called Clip-Two. I will give brief explaination about my problem.
Problem : In some of my pages the CSS works fine, however in some of the pages the partially loaded.
Below is my controller called Users.php
Users.php
Within this controller, i have two functions, mainly the first one is for index, and the second one is when i want to create a user.
In the first function, the CSS works fine. All the required CSS files are loaded shown below.
Index.php
However, in the second function, which have a new page, it only load partially of the whole CSS files.
Create.php
Below is my header template
header.php
The one that I highlight is the CSS file that doesnt loaded properly.
When I inspect the elements, the file path is wrong, shown below.
Elements
Below is my config file on base_url().
Base_url()
So, I'm confused, is it my base_url() went wrong or is it something else. Any help will be appreciated. Thanks in advance!.
Sorry I made a very long post, i just want everybody have a clear picture of my problem.
EDITED
I'm using admin template from Clip-Two
Below is the console error shown on my page.
Sorry I think my post is a bit misleading, I have edited my title and my problem
Problem : the jQuery from the template have the theme selector, so basically the jQuery could not find the path.
It shows that jQuery could not find the path.
Is this my problem lies on the jQuery?
Are you sure you are not manipulating with that stylesheet using JavaScript? (You have an id identifier on tag.)
Also, insted of <?php echo base_url()?>, try <?=base_url()?> it takes way less space.
Every other page on the site functions in such a way that the content entered into a page's meta tag page title field is inserted into that page's title element, but for some reason this isn't working for the homepage. I think it is using a previous description and won't update to the new one. I found this thread which seemed to be in relation to my problem but the main solutions didn't solve the problem.
Adding the PHP below into the bottom of the homepage node didn't solve the problem:
print render ($page['content']['metatags'])
or
print render ($content['metatags'])`
Has anyone else run into this problem and discovered another possible solution?
The error seems complex to get to it's cause so easy... but you can try the following code in a template of your frontpage (or asking inside a more generic template file if it's frontpage with drupal_is_front_page function):
print render(metatag_metatags_view('global:frontpage', array()));
That will print your metatags as far as I know.
If that does not work then you should debug every line of that function (metatag_metatags_view)... if you have access to the code of course... it's not pretty thing to do but there lies the root to your problem.
Hope that helps!
basically I need to use the scripts at verify.php. however when I navigate to mysite.com/verify.php, wordpress page shows up and throws 404.
I need to send AJAX post to this file from jQuery in the main wordpress index page.
As well as in the future I will have some more somescript.php to load via URL and I need wordpress to not throw 404.
You can create a custom page template. Within the custom page template you can include your own php code.
Before anyone can answer your question, please verify what is "verify.php", is it a file that you upload to /[your-wordpress-folder]/ or a custom page template ?
maybe his will help you :
http://codex.wordpress.org/Template_Hierarchy
http://codex.wordpress.org/Pages#Page_Templates
I've built my site with php include and the index is as follows:
Menu.php (menu system)
main.php (Index site)
footer.php (footer obv.)
Anyway, when main.php (index) opens, I've added a news script that uses $_GET to fetch the news-data from our mysql database. This generates an ID for each news, and it shows only a few characters of the full news.
So, I've added a link in each news that says "Read more" to expand the news, it looks like this:
Read More</p>
So, is there a way for me to include this site (replace news.php?id=x with main.php)?
It gives me syntax error when I'm trying to use <?php include in the link since it's already using <?=$row['id']?>.
The only help I got so far are people telling me to change the menu system to Javascript (Ajax, Jquery) but I'm not too familiar with this. Is there something I can do more simple than changing the menu to javascript?
Thanks for your help and understanding,
Have a great day!
Yeah, include basically adds the code of another file to the execution of the code you are using. So if you already have the variable in you index file can just use it in your menu file.
If the menu file has to be loaded on it own sometimes you can do a conditional for the existence of the GET, then the existence of the variable in your index file, and finally if none of them exit, set a default value.
leave your link as is, it's fine.
do not include main into news.
include only menu and footer into news.
Change it to main.php, get the id value on main.php, pass it to your news function.
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.