PHP通过短代码始终在页面顶部

时间:2017-09-20 09:29:29

标签: php wordpress shortcode

我有一个wordpress插件来显示最受欢迎的帖子......

但是当我通过短代码添加它时它总是到达页面顶部而不是我放置它的位置...我改变了插件PHP中的每个回显但是它没有帮助...这是我的functions.php中的短代码:

function top_news(){
	 $args = array(
    'limit' => 15,
    'range' => 'daily',
'freshness' => 1,
 'order_by' => 'views',
'post_type' => 'post',
'stats_views' => 1,
'stats_author' => 1,
 'stats_date' => 1,
'wpp_start' => '<table class="topnachrichten"><tr><th>Datum</th><th>Top Nachrichten von Heute</th><th>Leser</th></tr>',
    'wpp_end' => '</table>',
'stats_date_format' => 'd',
'excerpt_by_words' => 1,
    'excerpt_length' => 35,
'title_length' => 66,
 'post_html' => '<tr><td class="datum">{date}. Aug</td><td class="stext"><details>
  <summary><a href="{url}">{title}</a><span class="plus">+</span></summary>{summary}<br><a href="{url}">Weiterlesen</a></details></td><td class="views">{views}</td></tr>'


);
	wpp_get_mostpopular( $args );
	return $args;
}
add_shortcode( 'topnews', 'top_news' );

你知道我能做什么吗?

谢谢, 直到

1 个答案:

答案 0 :(得分:1)

阅读wpp_get_mostpopular的文档,它声明该函数实际打印了热门帖子。这意味着您的热门帖子会在返回任何内容之前打印出来,因为所有短代码都会在帖子内容被打印之前处理,这就是为什么您的热门帖子总是在帖子内容之前(顶部)打印的原因。

所以,你可以做的是在缓冲区中捕获所有热门帖子。

Param(
   [string]$baseurl = "http://server:8080/tfs/DefaultCollection",
   [string]$projectName = "ProjectName",
   [string]$keepForever = "true",
   [string]$user = "username",
   [string]$token = "token"
)

# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))

function CreateJsonBody
{

    $value = @"
[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "value": "0925Bug"
  },
  {
    "op": "add",
    "path": "/fields/System.AreaPath",
    "value": "LCScrum"
  },

  {
    "op": "add",
    "path": "/fields/System.IterationPath",
    "value": "LCScrum\\Sprint 1"
  },

  {
    "op": "add",
    "path": "/fields/System.Tags",
    "value": "Tag0921;Tag0926;Tag0927;Tag0928"
  },

  {
    "op": "add",
    "path": "/fields/Microsoft.VSTS.Common.Activity",
    "value": "Development"
  },

  {
    "op": "add",
    "path": "/fields/Microsoft.VSTS.Scheduling.Effort",
    "value": "8"
  },
  {
    "op": "add",
    "path": "/fields/Microsoft.VSTS.Common.ValueArea",
    "value": "Business"
  },
  {
    "op": "add",
    "path": "/fields/Microsoft.VSTS.Common.Severity",
    "value": "3 - Medium"
  },
  {
        "op": "add",
        "path": "/relations/-",
        "value":
        {
            "rel": "System.LinkTypes.Dependency-Forward",
            "url": "http://server:8080/tfs/DefaultCollection/_apis/wit/workItems/324",
            "attributes":
            {
               "usage": "workItemLink",
               "editable": false,
               "enabled": true,
               "acyclic": true,
               "directional": true,
               "singleTarget": true,
               "topology": "dependency"
            }
        }
    },
    {
        "op": "add",
        "path": "/relations/-",
        "value":
        {
            "rel": "System.LinkTypes.Hierarchy-Reverse",
            "url": "http://server:8080/tfs/DefaultCollection/_apis/wit/workItems/58",
            "attributes":
            {
              "usage": "workItemLink",
              "editable": false,
              "enabled": true,
              "acyclic": true,
              "directional": true,
              "singleTarget": false,
              "topology": "tree"
            }
        }
    }
]
"@

 return $value
}

$json = CreateJsonBody

$uri = "$baseurl/$($projectName)/_apis/wit/workitems/"+"$"+"bug?api-version=2.2"
Write-Host $uri
$result = Invoke-RestMethod -Uri $uri -Method Patch -Body $json -ContentType "application/json-patch+json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}