WordPress 插件在内容页面上输出特定类别调整帮助

发布于 2024-10-10 10:52:33 字数 1552 浏览 0 评论 0原文

我正在使用 WordPress 插件 类别页面 来显示某个类别的最新 5 篇帖子网站的常规内容页面(不是博客页面)。

目前该插件仅限于显示链接到帖子页面的帖子标题。这是一个视频博客类型的网站,我需要该插件来显示帖子标题(就像现在一样)和视频。可能只是告诉脚本显示内容就可以了,但我不知道如何调整它。

这是输出帖子标题的脚本部分:

function page2cat_content_catlist($content){
global $post;
    if ( stristr( $content, '[catlist' )) {
        $search = "@(?:<p>)*\s*\[catlist\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
        if  (preg_match_all($search, $content, $matches)) {
            if (is_array($matches)) {
                $title = get_option('p2c_catlist_title');
                if($title != "") $output = "<h4>".$title."</h4>"; else $output = "";
                $output .= "<ul class='p2c_catlist'>";
                $limit = get_option('p2c_catlist_limit');
                foreach ($matches[1] as $key =>$v0) {
                    $catposts = get_posts('category='.$v0."&numberposts=".$limit);
                        foreach($catposts as $single):
                        $output .= "<li><a href='".get_permalink($single->ID)." '>".$single->post_title."</a></li>";
                        endforeach;
                    $search = $matches[0][$key];
                    $replace= $output;
                    $content= str_replace ($search, $replace, $content);                    
                }
            $output .= "</ul>";
            }
        }
    }
return $content;
}

如果有人有任何建议或知道如何提供帮助,请提前致谢!

I'm using WordPress plugin Category Page to display the most recent 5 posts from a certain category on a regular content page (not the blog page) of a website.

Right now the plugin is limited to display the post title linked to the post page. This is a video blog type site and I need the plugin to display the post title (as it does now) with the video as well. Probably just telling the script to show the content would work but I don't know how to tweak it.

This is the section of the script that is outputting the post title:

function page2cat_content_catlist($content){
global $post;
    if ( stristr( $content, '[catlist' )) {
        $search = "@(?:<p>)*\s*\[catlist\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
        if  (preg_match_all($search, $content, $matches)) {
            if (is_array($matches)) {
                $title = get_option('p2c_catlist_title');
                if($title != "") $output = "<h4>".$title."</h4>"; else $output = "";
                $output .= "<ul class='p2c_catlist'>";
                $limit = get_option('p2c_catlist_limit');
                foreach ($matches[1] as $key =>$v0) {
                    $catposts = get_posts('category='.$v0."&numberposts=".$limit);
                        foreach($catposts as $single):
                        $output .= "<li><a href='".get_permalink($single->ID)." '>".$single->post_title."</a></li>";
                        endforeach;
                    $search = $matches[0][$key];
                    $replace= $output;
                    $content= str_replace ($search, $replace, $content);                    
                }
            $output .= "</ul>";
            }
        }
    }
return $content;
}

If anyone has any advice or knows how to help thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的往事 2024-10-17 10:52:33

在您的示例中,内容位于 $single->post_content 中。将其添加到 $output 中:

$output .= "

  • "。 $single->post_title."**".$single->post_content."**
  • ";

    The content is in $single->post_content in your example. Add it to the $output:

    $output .= "<li><a href='".get_permalink($single->ID)." '>".$single->post_title."**<span class='video'>".$single->post_content."<span>**</a></li>";

    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文