WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Expand specific posts on index, but not others (8 posts)

  1. dainismichel
    Member
    Posted 5 years ago #

    Hiya,

    Is there a way to expand specific posts on the index page, but not others? The checkbox would be something like "show expanded on index page," and of course, the HTML would remain in tact.

    :-)

    Best,
    Dainis

  2. stvwlf
    Member
    Posted 5 years ago #

    Hi

    A good way to do that would be to use a custom field on the posts you want expanded.

    Create a custom field called for example ExpandOnIndex and set it to true on all posts you want expanded on the index page.

    in index.php change your loop code. This is the coding from the default theme - most themes will be similar

    <div class="entry">
         <?php the_content('Read the rest of this entry &raquo;'); ?>
    </div>

    using my example, change it to this

    <div class="entry">
      <?php
      $expand = get_post_meta($post->ID, 'ExpandOnIndex', true);
      if ($expand) {
         the_content('Read the rest of this entry &raquo;');
      } else {
         the_excerpt();
      }
      ?>
    </div>

    The first part of this article is a tutorial on how to create a custom field, if you aren't familiar with that.
    http://forthelose.org/how-to-use-custom-fields-in-wordpress

  3. dainismichel
    Member
    Posted 5 years ago #

    Gosh, that works perfectly, I wish I understood the code better. Could someone translate the code into "English" so I can learn better?

    what does $ mean? Does that mean I am defining a variable?
    I think get_post_meta is likely a "function," but what does that mean?

    What a kind reply, I mean just posting the code like that. Thank you.

    :-)

    Dainis

  4. MichaelH
    Member
    Posted 5 years ago #

    PHP variables begin with a $

    To understand get_post_meta review:
    Using_Custom_Fields
    Function_Reference/get_post_meta

  5. dainismichel
    Member
    Posted 5 years ago #

    OK, that takes care of one php "code translation," and it points me in the right direction regarding what I "think" are called "wordpress functions." Thanks a ton!

    Now, coming from a linguistic perspective, how can I begin to "translate"

    <div class="entry">
    <?php
    $expand = get_post_meta($post->ID, 'ExpandOnIndex', true);

    into English, so that I can begin to "think" PHP code in English and then write it in PHP?

    <div class="entry"> =
    div (I don't know)
    class is a type of CSS style
    = is
    within quotes the name of the style

    <?php
    open carat = ?
    ? = I'm guessing here...uh...start code
    php = the type of code to start

    $expand = get_post_meta($post->ID, 'ExpandOnIndex', true);

    $ = begins PHP variables
    $expand = begin the variable called expand
    $expand = = defining the variable called expand

    get_post_meta($post->ID, 'ExpandOnIndex', true);
    the wordpress function, which I can set to particular parameters as outlined in the WordPress codex.

    OK, so, with what I did, can you guide me to a "linguistic translation" of PHP, or to a resource that explains coding in that manner?

    Best,
    Dainis

  6. MichaelH
    Member
    Posted 5 years ago #

    Probably better that I direct you to some other sources:
    CSS
    http://us2.php.net
    http://www.w3schools.com/php/
    http://www.w3schools.com/

  7. dainismichel
    Member
    Posted 5 years ago #

    Thanks Michael,

    Gotta love it!

    :-)

    --Dainis

  8. dainismichel
    Member
    Posted 4 years ago #

    Using a new theme and wanting to figure this out for

    <?php the_content_limit(410, ""); ?>

    ...I'll try some stuff out...

Topic Closed

This topic has been closed to new replies.

About this Topic