I am working on theme and i want to create page template may code is below :
<?php
/*
Template Name: Blog
*/
?>
<?php get_header(); ?>
<div id="content">
<div class="left">
<div class="pagina">
</div>
</div>
</div>
<?php get_footer(); ?>
I have creat page name Blog and assign it a custom template from dropdown Blog,But when I click on navigation element Blog it shows The requested URL /wp/blog/ was not found on this server.
anyone can help?
I'd suggest this is a permalink issue, not a template issue. Your .htaccess file should be writable and you should have some code automatically added to it when you set up the permalinks. Check that it is writable and try setting the permalinks up again. Failing that, I believe that WordPress gives you the code to copy/paste into it when you're setting up the permalinks.
In short, add this code to your .htaccess file, if it's not there already.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
That could be one of many reasons; either you have a blog template or it could be because you have not included the loop:
<?php
/*
Template Name: Archives with Content
*/
?>
<?php get_header(); ?>
<div id="content" class="">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<div class="left">
<h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
<div class="entrytext">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; endif; ?>
</div>
<div id="main">
<?php get_search_form(); ?>
<!-- and whatever else you need -->
</div>
<?php get_footer(); ?>
If that still does not work, try refreshing your permalinks
Related
I'm trying to display the data of a ACF but I'm getting this error in Visual Studio Code:
This is the entire code. I tried reinstalling the plugin, added PHP to the path but nothing seems to be working.
Single.php
<?php get_header();?>
<div class="container">
<div class="row">
<div>
<img src="<?php the_post_thumbnail_url('thumbnail'); ?>" id="single_header">
<div id="single_content">
<?php if (have_posts()):while (have_posts()):the_post(); ?>
<?php
$fn=get_the_author_meta('first_name');
$lname=get_the_author_meta('last_name');
$email=get_the_author_meta('email');
?>
<h1 class="text=cenetr nt-3 mb-5 text-primary"><?php the_title();?></h1>
<small>Publishor:<?php echo $fn; ?></small>
<p><?php the_content();?></p>
<?php
endwhile;
endif;
?>
<?php previous_post_link(); ?>
<?php next_post_link(); ?>
</div>
<div id="single_extraInfo">
<p>Company: <?php the_field('flight_company'); ?></p>
<p>Date: <?php the_field('flight_date'); ?></p>
<p>Capacity: <?php the_field('flight_capacity'); ?></p>
</div>
</div>
</div>
</div>
<?php get_footer(); ?>
On top of what #DaleNguyen adviced above...
Make sure the directory that contains acf plugin is in your Vs Code. Example, instead of only opening the theme directory in Vs Code in which you are probably working, open the entire wp_content directory in your VS Code. That way, when intelephence run in the back-ground, it will be able to reach the plugins folder and acf functions in the acf plugin folder.
In the intelephense, make sure you add wordpress to the list.
#james-serengia answered with one working solution that the ACF plugin folder should be open in the same workspace as the code you are working on and the warning disappears.
Alternatively if that is inconvenient, you can add you can add the ACF stubs to VSCode. It is a bit of messing around but when it is done, it is done. See this explanation.
So i had .htaccsess file with the following code
.htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
# Allowed the url has access to the php file without the .php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^folder/?$ - [F,L]
# Force remove .php extension, if manually changed in url
RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
RewriteRule ^ /%1 [NC,L,R]
</IfModule>
Options All -Indexes
ErrorDocument 403 /AllProject/layouts/403-page.php
ErrorDocument 404 /AllProject/layouts/404-page.php
ErrorDocument 500 /AllProject/layouts/500-page.php
So I want to create a restriction for users who don't have access to a certain url. When the user tries to access a certain url via the url address, the user will be redirected to a 404 page.
The function works but the 404 page doesn't display correctly, instead of using the error page from .htacess, but the standard 404 error from apache, the following code is
header function
<?php
// Check role
if ($_SESSION['role'] != 'ADMIN') {
header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found", true, 404);
die;
if (!isset($_SESSION['username']) && !isset($_SESSION['role'])) {
$containUrl = urlencode((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
header("Location: index?destination=" . $containUrl . "");
}
}
Then I tried using the require function, but that's also a problem because on the 404-page.php page I'm using require function too. Which make the file become to contradict. The file code is
404-page.php
<?php require '../koneksi/koneksi.php'; ?>
<?php require 'resources.php'; ?>
<body>
<!-- Page Container -->
<div class="page-container">
<div class="error-404">
<div class="error-bg"></div>
<div class="error-info">
<div class="error-text">
<div class="error-header">
<h3>404</h3>
</div>
<div class="error-body">
<p>Halaman yang anda cari tidak ditemukan.<br>Klik disini untuk kembali.
</div>
<div class="error-footer">
<p><?= date('Y') ?> © ReD | Projects <?= $version ?></p>
</div>
</div>
</div>
</div>
</div><!-- /Page Container -->
<?php require 'footer.php'; ?>
So where is the problem?
u try this code in .htaccess
#404 page
ErrorDocument 404 http://localhost/not-found.php
So, i've just figured it out to solve my problem.
Thanks to #CBroe at the comment to suggest me using DIR
It's actually working fine for me now.
So now in the 404-page.php now i am using
<?php require_once __DIR__ . '/../koneksi/koneksi.php' ?>
To require the file outside properly.
I'm practicing WordPress and are now stuck.
When I look at front-page.php in my browser, all pictures are visible, but when I look at page.php in the browser, none of the images are visible,
They both have identical paths to some images, yet page.php wont display any pictures, it is like it cant find the images or something.
I have tried to hardcode the img path, but with no luck.
Below is my Page.php code
<?php get_header();?> <!--- There are an image inside the header aswell, it will not display when I look at page.php in browser--->
<div class="container pt-5 pb-5">
<?php if (have_posts()) : while(have_posts()) : the_post();?>
<div class="row rounded p-5">
<?php the_content();?>
</div>
<?php endwhile; endif;?>
<img src="wp-content/themes/Newtheme/bilder/cosmic-heart-of-the-universe-shawn-dall.jpg">
</div>
<?php get_footer();?>
For example,
the user types in,
www.foob.com/some_path
I don't want to actually have a some_path folder for every different identifier the user might use ... for example if it is a person's name, as seen in many social apps.
www.foob.com/some_path1
However, i would like to read it in as a variable and serve the relevant content
JavaScript
var foo = 'some_path1'
PHP
$foo = 'some_path1';
How do I get 'some_path1' into foo?
Note
some_path is a variable, it might contain
some_path_1
some_path_2
some_path_3
Clarification
So take facebook.com
if you go to
www.facebook.com/your_name
it's not like there is a different directory for all 1 billion users.
A generic page is served populated with user specific data.
How do I get the id your_name?
You need to setup www.foob.com/some_path to point to a PHP script URL with index.php?q=some_path or similar in your .htaccess file:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-z\-]+)$ index.php?q=$1
Then it's just a matter of serving different content based on $_GET['q'] in the PHP file.
or to use it in Javascript:
echo '<script>...var q = ' . $_GET['q'] . ';</script>';
You can use $_SERVER['REQUEST_URI'] to get this information out with PHP. If you want it in JavaScript, take a look at the window.location object (probably window.location.href or window.location.pathname). Both might require a bit of parsing to only grab the part that you want, though.
Regarding the rewrite rule to send these requests to your script, I'd use something like this, which will redirect all requests for files that aren't found elsewhere through app.php. This should go in an .htaccess file on the root of your site.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
Add a .htaccess file to your root directory.
.htaccess
RewriteEngine On
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1 [L]
You can add something similar to this at the top of your index.php page:
<html>
<head>
<title> MyWebsite <?php echo '~'.ucwords($desired_page); ?> </title>
<?php
$page_array = array(
"home", "blog", "news",
"links", "about", "contact"
);
$desired_page = (isset($_REQUEST['page'])) ?
$_REQUEST['page'] : "home";
if(!in_array($desired_page, $page_array))
$desired_page = "error";
?>
</head>
<body>
<div id="menu">
<ul>
<li <?php if($desired_page=="home")
echo("class=\"current\""); ?>>
Home</li>
<li <?php if($desired_page=="blog")
echo("class=\"current\""); ?>>
Blog</li>
<li <?php if($desired_page=="news")
echo("class=\"current\""); ?>>
News</li>
<li <?php if($desired_page=="links")
echo("class=\"current\""); ?>>
Links</li>
<li <?php if($desired_page=="about")
echo("class=\"current\""); ?>>
About Us</li>
<li <?php if($desired_page=="contact")
echo("class=\"current\""); ?>>
Contact Us</li>
</ul>
</div><!--end menu-->
<div id="content">
<?php
/*Includes specific page content*/
include("content/".$desired_page.".php");
?>
</div> <!-- end #content -->
</body>
</html>
For some reason, the theme I've made won't turn the double newlines (pressing enter in the Visual editor) into paragraph tags. I tried disabling all plugins and it still doesn't work. It does work if I change to a default theme though. Any ideas?
<?php while ( have_posts() ) : the_post(); ?>
<div class="container">
<h2>
<?php the_title(); ?>
</h2>
</div> <!-- /container -->
<div class="container contentArea">
<?php the_content(); ?>
</div>
<?php endwhile; // end of the loop. ?>
I think that's done by the wpautop function (see here), which I thought was enabled by default (see here).
Perhaps you could add it manually to your theme? Or better, work out why it's not being enabled.