【问题标题】:getting post title and applying it to a url to fetch information from xml获取帖子标题并将其应用于 url 以从 xml 获取信息
【发布时间】:2011-04-02 15:31:56
【问题描述】:

这是我正在使用的代码,我会尽力解释我需要什么(我正在使用 wordpress)

function Count(){
$feed_url = "http://website.com/summary.xml?subfolder=POST TITLE";
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL,"$feed_url"); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0); 
$xmlFile = curl_exec($curl); 
curl_close($curl); 
$xml = simplexml_load_string($xmlFile); 
return $xml->count;
}

基本上我的网站会检查该网站的活动。如果它找到活动,它会说 ACTIVE,如果没有,它会说 Not Active。每个帖子都会查找与帖子标题对应的不同活动,例如:

“站点 A”有 Foobar 1、Foobar 2、Foobar 3。我的站点也与帖子标题具有相同的名称以查找活动。我不知道如何让帖子标题根据它对应的帖子动态变化。

我不能在 php 中使用 php 所以 php echo the_title();这是不可能的,但我需要它的确切作用,除非我不想回应它,我只需要将它放在 URL 的后面,这样网站就知道要为哪个帖子获取什么信息。

我认为这是有道理的, 任何帮助将不胜感激。

【问题讨论】:

    标签: wordpress post title


    【解决方案1】:

    我不确定我是否正确理解了您的问题,但如果我理解了,您不能像这样使用get_the_title() 将帖子标题添加到您的提要网址中吗(我假设您在循环中):

    $feed_url = "http://website.com/summary.xml?subfolder=".get_the_title();
    

    或者将它作为参数传递给你的函数:

    function Count($post_title){
        $feed_url = "http://website.com/summary.xml?subfolder=".$post_title;
        // ...
    

    并在循环中调用它:

    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    <?php $activity = Count(get_the_title()); ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-04
      • 2017-07-15
      • 2011-03-12
      • 2011-03-25
      • 1970-01-01
      • 2021-07-01
      • 1970-01-01
      • 2013-10-10
      相关资源
      最近更新 更多