【问题标题】:How to make custom posts in WordPress for a dummy?如何在 WordPress 中为假人制作自定义帖子?
【发布时间】:2012-01-30 00:57:14
【问题描述】:

我想知道的是,如何实现我已经制作的 index.php 文件以将自定义帖子应用到它。 (见下文)

我想要完成的事情:

Display all posts(already accomplished in index.php)
--> show normal post a.k.a 'Article' (already accomplished in index.php)

If category/or post type 'Aside' is used, don't apply a <a> tag, make title lighter(can figure it out in CSS)
-->show text for the 'Aside' marked post

If category/or post type 'Link' is used,  wrap title in <a> tag linking to a site(<-- how would I do that in WordPress?)  
-->show text for info about the link

If category/or post type 'Photo' is used, don't wrap title in a <a> tag
-->show attached image in post, and post text as a caption

我知道这可能看起来很多,但我相信它很容易做到。

有些源代码可能对我没有帮助,所以我在下面有我的 index.php 看看你是否可以帮我实现它:

<?php get_header(); ?>


<?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

        <div class="post" id="post-<?php the_ID(); ?>">

            <article>
            <!-- <p><span class="metaCat"><?php the_category(', '); ?></span></p> -->
            <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h1>
            <p><span class="meta"><?php the_time('F jS, Y') ?></span></p>
            <hr />
            <div class="entry">
                <?php the_content('Read the rest of this entry &raquo;'); ?>
            </div>

        </div>
</article>
        <hr class="big" />
    <?php endwhile; ?>



<?php else : ?>

    <h2 class="center">Not Found</h2>
    <p class="center">Sorry, but you are looking for something that isn't here.</p>
    <?php include (TEMPLATEPATH . "/searchform.php"); ?>

<?php endif; ?>

如果您可以将所需的代码输入到一个可行的 index.php 文件中,您将得到一些深思熟虑的布朗尼积分!

谢谢,欢迎所有帮助!

【问题讨论】:

    标签: php wordpress custom-post-type


    【解决方案1】:

    我终于明白你的意思了。这可以使用get_post_format() 函数轻松完成。只需将此处的标题替换为:

    <?php
    $format = get_post_format(get_the_ID());
    if ($format == 'link') { ?>
    <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php  the_title(); ?>"><?php the_title(); ?></a></h1>
    <?php }else{ ?>
        <h1><?php the_title(); ?></h1>
    <?php } ?>
    

    关于链接到网站的另一点,我不确定你想如何实现它。你指的是blogroll吗?

    “链接”帖子格式的最佳选择是使用自定义元框/自定义字段。将您的密钥添加为“URL”,然后在值字段中输入地址。

    使用get_post_meta() 获取URL 并在href 中使用它而不是the_permalink()

    【讨论】:

    • 我没有费心回答冗长的问题,因为大部分主题都在 forrst 中涵盖了。不需要太多人就能接受那里写的内容并根据他们的需要进行调整……更不用说对他们的查询进行正确的回答了。我离题了-因为第一个期望破灭了,第二个也将破灭。您的回复是准确的,但缺少关于帖子格式作为外部 uri 链接的部分。 (这需要一些 get_post_custom(get_the_ID()) 恶作剧)。
    • 至于 URL 部分......我想要完成的是 Tumblr 上已经完成的工作,基本上。有一个网站/文章的链接作为帖子的标题,就像我通过帖子分享它一样,上面有我写的 cmets。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多