WordPress.org

Ready to get started?Download WordPress

Forums

Add prefix to specific post (20 posts)

  1. Mo7sin
    Member
    Posted 1 year ago #

    i used this code to add prefix to specific post

    function add_podcast($title) {
    	if( in_category( 'foobar' ) ) $title = 'Podcast' . $title;
    	return $title;
    }
    add_filter('the_title', 'add_podcast');

    and i modified it to be "Updated" prefix

    function add_suffix($title) {
    	if( in_category( 'updated' ) ) $title =  $title . '<span class="updated">' . 'Updated'. '</span>';
    	return $title;
    }
    add_filter('the_title', 'add_suffix');

    but there is something went wrong

    see results

    http://imageshack.us/a/img832/5118/ccnplessonsonlinearabic.png

    Thanks in advance :)

  2. Peter_L
    Member
    Posted 1 year ago #

    Could you show a sample of the source code so I can see what the html looks like?

  3. Mo7sin
    Member
    Posted 1 year ago #

    @Peter

    this is the whole code

    function add_suffix($title) {
    	if( in_category( 'updated' ) ) $title =  $title . '<span class="updated">' . 'Updated'. '</span>';
    	return $title;
    }
    add_filter('the_title', 'add_suffix');
  4. Peter_L
    Member
    Posted 1 year ago #

    No no, I meant the front-end code. The actual html that gets shown in the browser.

  5. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    your theme seems to be falsely using the_title() instead of the_title_attribute() in the title attribute of the linked post title (possibly in index.php, if your image is from a front page posts?)

    general example of a linked post title with the right title attribute code:

    <a href="<?php the_permalink(); ?>" title="Permalink to <?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a>
  6. Mo7sin
    Member
    Posted 1 year ago #

    @alchymyth

    yes it worked with <?php the_title_attribute(); ?>

    but there is something needs to get edited here i believe because the styling is not working now :)

    function add_suffix($title) {
    	if( in_category( 'updated' ) ) $title =  $title . '<span class="updated">' . 'Updated'. '</span>';
    	return $title;
    }
    add_filter('the_title', 'add_suffix');
  7. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    for any styling problems, please post a link to your site to illustrate what is not working.

    a: nobody here knows how the styling is supposed to look;
    b: nobody can check anything, for instance with a browser inspection tool such a Firebug http://getfirebug.com/, to see how the styling is influenced.

  8. Mo7sin
    Member
    Posted 1 year ago #

    Sorry my bad

    http://ccnplessons.com/page/7/

    look @ post "06 – How Data TransfersUpdated"

    "updated" suppose to be

    .updated{float:right;color:#ff0000;}

    and it worked before i change <?php the_title(); ?> to <?php the_title_attribute(); ?>

  9. Peter_L
    Member
    Posted 1 year ago #

    There's a lot of things going wrong there.
    The span element seems to have been stripped but there's something else too. The entire span element has also been parsed inside the title attribute of a link below. (the watch this lesson button)

  10. Mo7sin
    Member
    Posted 1 year ago #

    yeah i think there is something wrong with original code, i dunno!

    function add_suffix($title) {
    	if( in_category( 'updated' ) ) $title =  $title . '<span class="updated">' . 'Updated'. '</span>';
    	return $title;
    }
    add_filter('the_title', 'add_suffix');
  11. Peter_L
    Member
    Posted 1 year ago #

    I'm thinking you're probably using a filter so you don't have to manually change each relevant template file, right?

    But you could do just that, add it manually in each template file:

    <?php if( in_category( 'updated' ) ){
    echo '<span class="updated">Updated</span>';
    }?>
  12. Mo7sin
    Member
    Posted 1 year ago #

    i added it to every template file and it does nothing.

  13. Peter_L
    Member
    Posted 1 year ago #

    I tested this line, worked for me. Where did you place it? Could you show snippet?

  14. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    and it worked before i change <?php the_title(); ?> to <?php the_title_attribute(); ?>

    you only change this witin the title attribute, not the actual title;

    I posted an exact example already:

    <a href="<?php the_permalink(); ?>" title="Permalink to <?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a>

    so there is this part (the title attribute part):
    title="Permalink to <?php the_title_attribute(); ?>"

    and then there is (the title directly):
    <?php the_title(); ?>

  15. Mo7sin
    Member
    Posted 1 year ago #

    @alchymyth

    it worked now .. thank you for help

    now i have another problem .. when you browse the category that has an updated post .. the menus are effected too, check here

    http://ccnplessons.com/lessons/ccna/network-introduction/

    ===========================================

    @Peter_L
    the filter worked itself without your code,
    it was in the bottom of my template files :)

  16. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    add another conditional check into your filter:

    http://codex.wordpress.org/Function_Reference/in_the_loop

    function add_suffix($title) {
    	if( in_the_loop() && in_category( 'updated'  ) ) $title =  $title . '<span class="updated">' . 'Updated'. '</span>';
    	return $title;
    }
    add_filter('the_title', 'add_suffix');
  17. Peter_L
    Member
    Posted 1 year ago #

    You're having in issue in your actual posts too. The string 'Updated" />' appears above the header.

    Also, in your source code, there's an enormous amount of caching data parsed in your footer. I'm guessing you've switched a debug option on in your w3c caching plugin. You might want to fix that.

  18. Mo7sin
    Member
    Posted 1 year ago #

    Works great :)
    i'm really shy to ask again

    i got unnecessary "Updated" inside the post

    http://ccnplessons.com/frame-relay/

    Thanks in advance.

  19. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    unfortunately, the filter on 'the_title' is not very specific;

    you might need to attack that using css;

    try for example:

    .updated { display: none; }
    
    .cover .updated, h1 .updated { display: block; }
  20. Mo7sin
    Member
    Posted 1 year ago #

    It works .. thank you very much :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags