简体   繁体   English

如何在WordPress中为假人创建自定义帖子?

[英]How to make custom posts in WordPress for a dummy?

What I want to know is, how can I implement my already made index.php file to apply custom posts to it. 我想知道的是,如何实现已经完成的index.php文件以将自定义帖子应用到该文件。 (See below) (见下文)

What I want to accomplish: 我要完成的工作:

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

I know this may look like a lot but I'm sure it's easily do-able. 我知道这看起来很多,但我确信它很容易实现。

Some source code may not help me all the way, so I have my index.php below to see if you can help me implement it into it: 某些源代码可能不会完全帮助我,因此下面有我的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; ?>

If you can input the needed code into a workable index.php file you will get some well thought of brownie points! 如果您可以将所需的代码输入到可行的index.php文件中,那么您将对布朗尼点有所了解!

Thanks and all help is welcomed! 谢谢,欢迎大家的帮助!

I finally see what you meant to do here. 我终于明白了你打算在这里做什么。 This is easily done using the get_post_format() function. 使用get_post_format()函数可以轻松完成此操作。 Just replace the title here with: 只需将标题替换为:

<?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 } ?>

The other bit about linking to a site though, I'm not sure how you want to accomplish that. 不过,关于链接到网站的其他问题,我不确定您要如何实现。 Are you referring to the blogroll? 您指的是Blogroll吗?

The best option for the "link" post format, is to use a custom metabox/custom fields. “链接”发布格式的最佳选择是使用自定义metabox /自定义字段。 Add your key as "URL" then type the address in the value field. 将密钥添加为“ URL”,然后在值字段中输入地址。

Use get_post_meta() to get the URL and use that instead of the_permalink() in the href. 使用get_post_meta()获取URL并使用它代替href中的the_permalink()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM