我是Wordpress的新手,所以请原谅我。
我正在从一个wordpress页面导航到另一个页面,链接如下:
<a href="<?php echo site_url(); ?>/wp-content/themes/woffice-child-theme/page-templates/loginF.php"><img src="./wp-content/themes/woffice-child-theme/page-templates/images/signin-btn.png"></a>
logif .php确实加载,但从页面的任何地方我调用任何wordpress函数,如home_url()或wp_login_form()页面停止渲染。例如,如果我将home_url()放在页面的开头,那么我将在浏览器中得到一个空页面。为什么会发生这种情况?我是不是脱离了wordpress环境?该怎么办?
这里是logif .php:
<html>
<?php
$redirect_url = home_url();
?>
<head>
<title>Title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="/wp-content/themes/woffice-child-theme/page-templates/style2.css">
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,300' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="frontpage-content">
<div class="front-wrap">
<br/>
<div class="new-login-logo text-center"><img src="/wp-content/themes/woffice-child-theme/page-templates/images/new-login-logo.png"></div>
<br/><br/>
<div class="frontpage-fields">
<input type="text" name="log" id="user" class="input" placeholder="Email Address">
<input type="password" name="pwd" id="pass" class="input" placeholder="Password">
</div>
<div class="forgot-password-new"><a href="#">Forgot your password?</a></div>
<br/>
<div class="text-center"><a href="#"><img src="./images/captcha-image.png"></a></div>
<br/>
<div class="text-center new-login-space"><a href="#"><img src="/wp-content/themes/woffice-child-theme/page-templates/images/new-login-btn.png"></a></div>
</div>
</div>
</body>
</html>
按照WordPress标准创建一个新的页面模板。
<?php
/**
* Template Name: My Custom Page
*/
get_header(); ?>
<!-- Your code goes here -->
<?php get_footer(); ?>
https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/然后从WordPress后端创建一个新页面,并选择您的页面模板名称(模板名称在模板文件的头调用之前给出)作为后端模板&保存页面
在发布按钮下面的页面属性部分,我们可以选择页面模板。
附加截图
最后,在锚标记中调用这个新的页面URL作为href
值,而不是调用模板文件。
我们可以从页面标题或页面段符中获取页面URL。
get_permalink( get_page_by_path( 'your-page-slug' ) )
get_permalink( get_page_by_title( 'Your page title' ) )
这是整个页面的html吗?它应该以
开头 <?php get_header(); ?>
并以
结尾 <?php get_footer(); ?>
您应该将您的页面模板分配给Wordpress中的任何页面,然后使用页面url而不是使用当前。现在你用错了方法。请改正。另外,不要忘记在模板中调用get_header()和get_footer()。
好吧,也许我们可以用另一种方式来解决。你的链接链接到一个页面模板,而不是一个URL,这是有点奇怪。这可能会导致Wordpress陷入无限循环。
我可以问一下你为什么要链接到这个吗?它是定制样式的登录页面吗?因为还有其他解决方案。
你可以通过在你的themes functions.php
中放置这段代码来改变普通Wordpress登录页面上的logo // log in logo link
add_filter( 'login_headerurl', 'custom_loginlogo_url' );
function custom_loginlogo_url($url) {
return 'http://www.yourlink.co.uk';
}
// login logo
function my_login_logo() { ?>
<style type="text/css">
body.login div#login h1 a {
background-image: url(<?php echo get_stylesheet_directory_uri(); ?>/library/images/logo.png);
padding-bottom: 15px;
height: 74px;
width: auto;
background-size: 60% auto;
}
</style>
<?php }
add_action( 'login_enqueue_scripts', 'my_login_logo' );
然后直接链接到www.yourdomain.co.uk/wp-admin
但是,如果您要使用自定义登录页面,请使用当前可用的模板文件,该文件应该以如下内容打开
<?php /* Template Name: my-template */ ?>
并包含在该页中。然后在Wordpress admin中创建一个页面,并选择模板"my-template"并链接到该页面的URL。