使搜索和档案匹配主页

发布于 2024-12-06 20:09:43 字数 1018 浏览 7 评论 0原文

我将主页 http://www.faberunashop.com 设置为目录。当您单击帖子图像时,它会将您带到艺术家网站。以下是我用来实现此目的的代码,将其添加到functions.php:

function print_post_title() {
    global $post;
    $thePostID = $post->ID;
    $post_id = get_post($thePostID);
    $title = $post_id->post_title;
    $perm  = get_permalink($post_id);
    $post_keys = array(); $post_val  = array();
    $post_keys = get_post_custom_keys($thePostID);

    if (!empty($post_keys)) {
      foreach ($post_keys as $pkey) {
            if ($pkey=='url1' || $pkey=='title_url' || $pkey=='url_title') {
              $post_val = get_post_custom_values($pkey);
            }
      }
      if (empty($post_val)) {
            $link = $perm;
      } else {
            $link = $post_val[0];
      }
    } else {
      $link = $perm;
    }
    echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>';
}

现在我想对我的搜索和存档页面执行相同的操作。我该如何调整才能使它们表现相同?

I have my homepage http://www.faberunashop.com set up as a directory. When you click on the post image, it takes you over to the artists site. Here is the code that I used to make this happen by adding it to the functions.php:

function print_post_title() {
    global $post;
    $thePostID = $post->ID;
    $post_id = get_post($thePostID);
    $title = $post_id->post_title;
    $perm  = get_permalink($post_id);
    $post_keys = array(); $post_val  = array();
    $post_keys = get_post_custom_keys($thePostID);

    if (!empty($post_keys)) {
      foreach ($post_keys as $pkey) {
            if ($pkey=='url1' || $pkey=='title_url' || $pkey=='url_title') {
              $post_val = get_post_custom_values($pkey);
            }
      }
      if (empty($post_val)) {
            $link = $perm;
      } else {
            $link = $post_val[0];
      }
    } else {
      $link = $perm;
    }
    echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>';
}

Now I want to do the same to my search and archive page. What do I adjust to make them behave the same?

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

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

发布评论

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

评论(1

夏至、离别 2024-12-13 20:09:43

我猜你用的是 WordPress。

在这种情况下,您可以通过在搜索结果主题中创建一个名为 search.php 的文件,以及另一个名为 archives.php 的档案文件来更改搜索结果的布局和行为。

有关 WordPress 模板层次结构的更多信息,您可以在此处找到 http://codex.wordpress.org/Template_Hierarchy

I suppose that you use WordPress.

In that case you can change the layout and the behavior of your search results by creating a file with name search.php into your theme for your search results, and another file for archives that called archives.php.

For more information about Template Hierarchy for WordPress you can find here http://codex.wordpress.org/Template_Hierarchy

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