我试图告诉我的 WordPress 模板使用特定的开放图形图像,如果它当前在主页上。WordPress 有一个内置功能来确定您当前是否在主页上:
is_front_page().
Run Code Online (Sandbox Code Playgroud)
我的模板在 header.php 中有这个:
<meta property="og:image" content="<?php echo the_post_thumbnail_url('mint-full-post'); ?>" />
Run Code Online (Sandbox Code Playgroud)
我把它改成这样:
<meta property="og:image" content="<?php is_front_page() ? echo 'http://rainydaystories.com/wp-content/uploads/social.jpg' : echo the_post_thumbnail_url('mint-full-post'); ?>" />
Run Code Online (Sandbox Code Playgroud)
这会导致网站崩溃。我做错了什么,谁能帮我找到更好的解决方案?谢谢!
在我的课堂上,我试图在除以外的函数中设置变量的值 __construct()
但我需要另一个函数中的变量值.
这是我尝试过的.但不能正常工作.
我希望打印getty images但我一无所获:(
<?php
class MyClass{
public $var;
public function __construct(){
$this->var;
}
public function setval(){
$this->var = 'getty Images';
}
public function printval(){
echo $this->var;
}
}
$test = new MyClass();
$test->printval();
Run Code Online (Sandbox Code Playgroud) 这是我编写的用于抓取“blablacar”网站的代码。
# -*- coding: utf-8 -*-
import scrapy
class BlablaSpider(scrapy.Spider):
name = 'blabla'
allowed_domains = ['blablacar.in']
start_urls = ['http://www.blablacar.in/ride-sharing/new-delhi/chandigarh']
def parse(self, response):
print(response.text)
Run Code Online (Sandbox Code Playgroud)
运行上述程序时,我收到错误消息
2018-06-11 00:07:05 [scrapy.extensions.telnet] 调试:Telnet 控制台监听 127.0.0.1:6023 2018-06-11 00:07:06 [scrapy.core.engine] 调试:爬行 (403) ) http://www.blablacar.in/robots.txt> (referer: None) 2018-06-11 00:07:06 [scrapy.core.engine] DEBUG: Crawled (403) http://www.blablacar .in/ride-sharing/new-delhi/chandigarh> (referer: None) 2018-06-11 00:07:06 [scrapy.spidermiddlewares.httperror] INFO:忽略响应 <403 http://www.blablacar.in /ride-sharing/new-delhi/chandigarh >: HTTP 状态代码未处理或不允许 2018-06-11 00:07:06 [scrapy.core.engine] INFO: Closing spider (finished)
我将网站设置存储在如下表中:
+---------+-------------+
| id | value |
+---------+-------------+
| 1 | title |
| 2 | description |
| 3 | email |
| 4 | keywords |
+---------+-------------+
Run Code Online (Sandbox Code Playgroud)
如何选择它们并将它们分配给变量($ title,$ desc,$ email,$ key)
// Get Website Infos
$result=$db->query("SELECT `value` FROM `settings`");
if($result->num_rows >= 1){
$row=$result->fetch_assoc();
$otitle=$row['value'];
$odescription=$row['value'];
$oemail=$row['value'];
$okeywords=$row['value'];
}
Run Code Online (Sandbox Code Playgroud)
但它只获得第一行'标题',任何想法如何做或更好的方法来保存设置.
更新:
如果您现在正在阅读此问题,请不要使用此结构来存储您的设置,在答案中使用Yellow Bird建议的那个.