• Resolved dainismichel

    (@dainismichel)


    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

Viewing 7 replies - 1 through 7 (of 7 total)
  • stvwlf

    (@stvwlf)

    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

    Thread Starter dainismichel

    (@dainismichel)

    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

    MichaelH

    (@michaelh)

    PHP variables begin with a $

    To understand get_post_meta review:
    Using_Custom_Fields
    Function_Reference/get_post_meta

    Thread Starter dainismichel

    (@dainismichel)

    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

    MichaelH

    (@michaelh)

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

    Thread Starter dainismichel

    (@dainismichel)

    Thanks Michael,

    Gotta love it!

    🙂

    –Dainis

    Thread Starter dainismichel

    (@dainismichel)

    Using a new theme and wanting to figure this out for

    <?php the_content_limit(410, “”); ?>

    …I’ll try some stuff out…

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Expand specific posts on index, but not others’ is closed to new replies.